From 13b536ebda4866063091f75e0ab97a4839cf9309 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 20 Jul 2023 10:04:46 +0000 Subject: [PATCH] deploy: fd45a8219a3aa2851232025b26f331fb6a898083 --- 404.html | 4 ++-- assets/js/0a887687.0cb8b9f7.js | 1 + assets/js/0a887687.a6a0d0f0.js | 1 - .../{runtime~main.225127f3.js => runtime~main.b3e20785.js} | 2 +- docs/Tutorials/Middlewares/index.html | 4 ++-- docs/Tutorials/Middlewares/logging/index.html | 4 ++-- docs/Tutorials/Middlewares/metrics/index.html | 4 ++-- docs/Tutorials/connect/index.html | 4 ++-- docs/Tutorials/connect_background/index.html | 4 ++-- docs/Tutorials/custom_codec/index.html | 4 ++-- docs/Tutorials/publish/index.html | 4 ++-- docs/Tutorials/subscribe/index.html | 4 ++-- docs/getting-started/index.html | 4 ++-- docs/sdk/index.html | 6 +++--- docs/sdk/otelcourier/index.html | 4 ++-- docs/sdk/xds/backoff/index.html | 4 ++-- docs/sdk/xds/bootstrap/index.html | 4 ++-- docs/sdk/xds/index.html | 4 ++-- docs/sdk/xds/log/index.html | 4 ++-- index.html | 4 ++-- 20 files changed, 37 insertions(+), 37 deletions(-) create mode 100644 assets/js/0a887687.0cb8b9f7.js delete mode 100644 assets/js/0a887687.a6a0d0f0.js rename assets/js/{runtime~main.225127f3.js => runtime~main.b3e20785.js} (91%) diff --git a/404.html b/404.html index 3815ee5..9072305 100644 --- a/404.html +++ b/404.html @@ -4,13 +4,13 @@ Page Not Found | Courier Go - +
Skip to main content

Page Not Found

We could not find what you were looking for.

Please contact the owner of the site that linked you to the original URL and let them know their link is broken.

- + \ No newline at end of file diff --git a/assets/js/0a887687.0cb8b9f7.js b/assets/js/0a887687.0cb8b9f7.js new file mode 100644 index 0000000..af99465 --- /dev/null +++ b/assets/js/0a887687.0cb8b9f7.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkcourier=self.webpackChunkcourier||[]).push([[990],{3905:(e,t,n)=>{n.d(t,{Zo:()=>u,kt:()=>g});var r=n(7294);function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}var c=r.createContext({}),s=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},u=function(e){var t=s(e.components);return r.createElement(c.Provider,{value:t},e.children)},p="mdxType",b={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,i=e.mdxType,a=e.originalType,c=e.parentName,u=l(e,["components","mdxType","originalType","parentName"]),p=s(n),m=i,g=p["".concat(c,".").concat(m)]||p[m]||b[m]||a;return n?r.createElement(g,o(o({ref:t},u),{},{components:n})):r.createElement(g,o({ref:t},u))}));function g(e,t){var n=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var a=n.length,o=new Array(a);o[0]=m;var l={};for(var c in t)hasOwnProperty.call(t,c)&&(l[c]=t[c]);l.originalType=e,l[p]="string"==typeof e?e:i,o[1]=l;for(var s=2;s{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>o,default:()=>b,frontMatter:()=>a,metadata:()=>l,toc:()=>s});var r=n(7462),i=(n(7294),n(3905));const a={},o=void 0,l={unversionedId:"sdk/SDK",id:"sdk/SDK",title:"SDK",description:"Package courier contains the client that can be used to interact with the courier infrastructure to publish/subscribe to messages from other clients",source:"@site/docs/sdk/SDK.md",sourceDirName:"sdk",slug:"/sdk/",permalink:"/courier-go/docs/sdk/",draft:!1,editUrl:"https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/docs/sdk/SDK.md",tags:[],version:"current",frontMatter:{},sidebar:"tutorialSidebar",previous:{title:"Subscribe Messages",permalink:"/courier-go/docs/Tutorials/subscribe"},next:{title:"otelcourier",permalink:"/courier-go/docs/sdk/otelcourier"}},c={},s=[{value:"Index",id:"index",level:2},{value:"Variables",id:"variables",level:2}],u={toc:s},p="wrapper";function b(e){let{components:t,...n}=e;return(0,i.kt)(p,(0,r.Z)({},u,n,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("h1",{id:"courier"},"courier"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},'import "github.com/gojek/courier-go"\n')),(0,i.kt)("p",null,"Package courier contains the client that can be used to interact with the courier infrastructure to publish/subscribe to messages from other clients"),(0,i.kt)("h2",{id:"index"},"Index"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#variables"},"Variables")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#ExponentialStartStrategy"},"func ExponentialStartStrategy","(","ctx context.Context, c interface","{"," Start","(",")"," error ","}",", opts ...StartOption",")")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#Version"},"func Version","(",")"," string")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#WaitForConnection"},"func WaitForConnection","(","c ConnectionInformer, waitFor time.Duration, tick time.Duration",")"," bool")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#Client"},"type Client"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#NewClient"},"func NewClient","(","opts ...ClientOption",")"," ","(","*","Client, error",")")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#Client.IsConnected"},"func ","(","c ","*","Client",")"," IsConnected","(",")"," ","(","online bool",")")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#Client.Publish"},"func ","(","c ","*","Client",")"," Publish","(","ctx context.Context, topic string, message interface","{","}",", opts ...Option",")"," error")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#Client.Run"},"func ","(","c ","*","Client",")"," Run","(","ctx context.Context",")"," error")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#Client.Start"},"func ","(","c ","*","Client",")"," Start","(",")"," ","(","err error",")")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#Client.Stop"},"func ","(","c ","*","Client",")"," Stop","(",")")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#Client.Subscribe"},"func ","(","c ","*","Client",")"," Subscribe","(","ctx context.Context, topic string, callback MessageHandler, opts ...Option",")"," error")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#Client.SubscribeMultiple"},"func ","(","c ","*","Client",")"," SubscribeMultiple","(","ctx context.Context, topicsWithQos map","[","string","]","QOSLevel, callback MessageHandler",")"," error")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#Client.Unsubscribe"},"func ","(","c ","*","Client",")"," Unsubscribe","(","ctx context.Context, topics ...string",")"," error")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#Client.UsePublisherMiddleware"},"func ","(","c ","*","Client",")"," UsePublisherMiddleware","(","mwf ...PublisherMiddlewareFunc",")")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#Client.UseSubscriberMiddleware"},"func ","(","c ","*","Client",")"," UseSubscriberMiddleware","(","mwf ...SubscriberMiddlewareFunc",")")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#Client.UseUnsubscriberMiddleware"},"func ","(","c ","*","Client",")"," UseUnsubscriberMiddleware","(","mwf ...UnsubscriberMiddlewareFunc",")")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#ClientOption"},"type ClientOption"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#WithAddress"},"func WithAddress","(","host string, port uint16",")"," ClientOption")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#WithAutoReconnect"},"func WithAutoReconnect","(","autoReconnect bool",")"," ClientOption")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#WithCleanSession"},"func WithCleanSession","(","cleanSession bool",")"," ClientOption")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#WithClientID"},"func WithClientID","(","clientID string",")"," ClientOption")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#WithConnectTimeout"},"func WithConnectTimeout","(","duration time.Duration",")"," ClientOption")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#WithCustomDecoder"},"func WithCustomDecoder","(","decoderFunc DecoderFunc",")"," ClientOption")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#WithCustomEncoder"},"func WithCustomEncoder","(","encoderFunc EncoderFunc",")"," ClientOption")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#WithExponentialStartOptions"},"func WithExponentialStartOptions","(","options ...StartOption",")"," ClientOption")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#WithGracefulShutdownPeriod"},"func WithGracefulShutdownPeriod","(","duration time.Duration",")"," ClientOption")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#WithKeepAlive"},"func WithKeepAlive","(","duration time.Duration",")"," ClientOption")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#WithMaintainOrder"},"func WithMaintainOrder","(","maintainOrder bool",")"," ClientOption")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#WithMaxReconnectInterval"},"func WithMaxReconnectInterval","(","duration time.Duration",")"," ClientOption")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#WithOnConnect"},"func WithOnConnect","(","handler OnConnectHandler",")"," ClientOption")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#WithOnConnectionLost"},"func WithOnConnectionLost","(","handler OnConnectionLostHandler",")"," ClientOption")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#WithOnReconnect"},"func WithOnReconnect","(","handler OnReconnectHandler",")"," ClientOption")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#WithPassword"},"func WithPassword","(","password string",")"," ClientOption")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#WithPersistence"},"func WithPersistence","(","store Store",")"," ClientOption")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#WithResolver"},"func WithResolver","(","resolver Resolver",")"," ClientOption")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#WithTCPAddress"},"func WithTCPAddress","(","host string, port uint16",")"," ClientOption")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#WithTLS"},"func WithTLS","(","tlsConfig ","*","tls.Config",")"," ClientOption")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#WithUseBase64Decoder"},"func WithUseBase64Decoder","(",")"," ClientOption")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#WithUsername"},"func WithUsername","(","username string",")"," ClientOption")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#WithWriteTimeout"},"func WithWriteTimeout","(","duration time.Duration",")"," ClientOption")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#ConnectionInformer"},"type ConnectionInformer")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#Decoder"},"type Decoder"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#DefaultDecoderFunc"},"func DefaultDecoderFunc","(","_"," context.Context, r io.Reader",")"," Decoder")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#DecoderFunc"},"type DecoderFunc")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#Encoder"},"type Encoder"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#DefaultEncoderFunc"},"func DefaultEncoderFunc","(","_"," context.Context, w io.Writer",")"," Encoder")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#EncoderFunc"},"type EncoderFunc")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#Message"},"type Message"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#NewMessageWithDecoder"},"func NewMessageWithDecoder","(","payloadDecoder Decoder",")"," ","*","Message")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#Message.DecodePayload"},"func ","(","m ","*","Message",")"," DecodePayload","(","v interface","{","}",")"," error")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#MessageHandler"},"type MessageHandler")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#OnConnectHandler"},"type OnConnectHandler")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#OnConnectionLostHandler"},"type OnConnectionLostHandler")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#OnReconnectHandler"},"type OnReconnectHandler")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#Option"},"type Option")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#PubSub"},"type PubSub")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#Publisher"},"type Publisher")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#PublisherFunc"},"type PublisherFunc"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#PublisherFunc.Publish"},"func ","(","f PublisherFunc",")"," Publish","(","ctx context.Context, topic string, message interface","{","}",", opts ...Option",")"," error")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#PublisherMiddlewareFunc"},"type PublisherMiddlewareFunc"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#PublisherMiddlewareFunc.Middleware"},"func ","(","pmw PublisherMiddlewareFunc",")"," Middleware","(","publisher Publisher",")"," Publisher")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#QOSLevel"},"type QOSLevel")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#Resolver"},"type Resolver")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#Retained"},"type Retained")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#StartOption"},"type StartOption"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#WithMaxInterval"},"func WithMaxInterval","(","interval time.Duration",")"," StartOption")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#WithOnRetry"},"func WithOnRetry","(","retryFunc func","(","error",")",")"," StartOption")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#Store"},"type Store"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#NewMemoryStore"},"func NewMemoryStore","(",")"," Store")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#Subscriber"},"type Subscriber")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#SubscriberFuncs"},"type SubscriberFuncs"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#NewSubscriberFuncs"},"func NewSubscriberFuncs","(","subscribeFunc func","(","context.Context, string, MessageHandler, ...Option",")"," error, subscribeMultipleFunc func","(","context.Context, map","[","string","]","QOSLevel, MessageHandler",")"," error",")"," SubscriberFuncs")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#SubscriberFuncs.Subscribe"},"func ","(","s SubscriberFuncs",")"," Subscribe","(","ctx context.Context, topic string, callback MessageHandler, opts ...Option",")"," error")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#SubscriberFuncs.SubscribeMultiple"},"func ","(","s SubscriberFuncs",")"," SubscribeMultiple","(","ctx context.Context, topicsWithQos map","[","string","]","QOSLevel, callback MessageHandler",")"," error")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#SubscriberMiddlewareFunc"},"type SubscriberMiddlewareFunc"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#SubscriberMiddlewareFunc.Middleware"},"func ","(","smw SubscriberMiddlewareFunc",")"," Middleware","(","subscriber Subscriber",")"," Subscriber")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#TCPAddress"},"type TCPAddress")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#Unsubscriber"},"type Unsubscriber")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#UnsubscriberFunc"},"type UnsubscriberFunc"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#UnsubscriberFunc.Unsubscribe"},"func ","(","f UnsubscriberFunc",")"," Unsubscribe","(","ctx context.Context, topics ...string",")"," error")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#UnsubscriberMiddlewareFunc"},"type UnsubscriberMiddlewareFunc"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("a",{parentName:"li",href:"#UnsubscriberMiddlewareFunc.Middleware"},"func ","(","usmw UnsubscriberMiddlewareFunc",")"," Middleware","(","unsubscriber Unsubscriber",")"," Unsubscriber"))))),(0,i.kt)("h2",{id:"variables"},"Variables"),(0,i.kt)("a",{name:"ErrConnectTimeout"}),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},'var (\n // ErrConnectTimeout indicates connection timeout while connecting to broker.\n ErrConnectTimeout = errors.New("client timed out while trying to connect to the broker")\n // ErrPublishTimeout indicates publish timeout.\n ErrPublishTimeout = errors.New("publish timeout")\n // ErrSubscribeTimeout indicates subscribe timeout.\n ErrSubscribeTimeout = errors.New("subscribe timeout")\n // ErrUnsubscribeTimeout indicates unsubscribe timeout.\n ErrUnsubscribeTimeout = errors.New("unsubscribe timeout")\n // ErrSubscribeMultipleTimeout indicates multiple subscribe timeout.\n ErrSubscribeMultipleTimeout = errors.New("subscribe multiple timeout")\n)\n')),(0,i.kt)("a",{name:"ExponentialStartStrategy"}),"## func [ExponentialStartStrategy](https://github.com/gojek/courier-go/blob/main/exp_starter.go#L32)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func ExponentialStartStrategy(ctx context.Context, c interface{ Start() error }, opts ...StartOption)\n")),(0,i.kt)("p",null,"ExponentialStartStrategy will keep attempting to call Client.Start in the background and retry on error, it will never exit unless the context used to invoke is cancelled. This will NOT stop the client, that is the responsibility of caller."),(0,i.kt)("a",{name:"Version"}),"## func [Version](https://github.com/gojek/courier-go/blob/main/version.go#L4)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func Version() string\n")),(0,i.kt)("p",null,"Version can be used to get the current courier library version"),(0,i.kt)("a",{name:"WaitForConnection"}),"## func [WaitForConnection](https://github.com/gojek/courier-go/blob/main/utils.go#L10)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func WaitForConnection(c ConnectionInformer, waitFor time.Duration, tick time.Duration) bool\n")),(0,i.kt)("p",null,"WaitForConnection checks if the Client is connected, it calls ConnectionInformer.IsConnected after every tick and waitFor is the maximum duration it can block. Returns true only when ConnectionInformer.IsConnected returns true"),(0,i.kt)("a",{name:"Client"}),"## type [Client](https://github.com/gojek/courier-go/blob/main/client.go#L17-L29)",(0,i.kt)("p",null,"Client allows to communicate with an MQTT broker"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type Client struct {\n // contains filtered or unexported fields\n}\n")),(0,i.kt)("a",{name:"NewClient"}),"### func [NewClient](https://github.com/gojek/courier-go/blob/main/client.go#L34)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func NewClient(opts ...ClientOption) (*Client, error)\n")),(0,i.kt)("p",null,"NewClient creates the Client struct with the clientOptions provided, it can return error when prometheus.DefaultRegisterer has already been used to register the collected metrics"),(0,i.kt)("details",null,(0,i.kt)("summary",null,"Example"),(0,i.kt)("p",null,(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},'c, err := courier.NewClient(\n courier.WithUsername("username"),\n courier.WithPassword("password"),\n courier.WithAddress("localhost", 1883),\n)\n\nif err != nil {\n panic(err)\n}\n\nif err := c.Start(); err != nil {\n panic(err)\n}\n\nstopCh := make(chan os.Signal, 1)\nsignal.Notify(stopCh, []os.Signal{os.Interrupt, syscall.SIGTERM}...)\n\ngo func() {\n tick := time.NewTicker(time.Second)\n for {\n select {\n case t := <-tick.C:\n msg := map[string]interface{}{\n "time": t.UnixNano(),\n }\n if err := c.Publish(context.Background(), "topic", msg, courier.QOSOne); err != nil {\n fmt.Printf("Publish() error = %s\\n", err)\n } else {\n fmt.Println("Publish() success")\n }\n case <-stopCh:\n tick.Stop()\n return\n }\n }\n}()\n\n<-stopCh\nc.Stop()\n')))),(0,i.kt)("a",{name:"Client.IsConnected"}),"### func \\(\\*Client\\) [IsConnected](https://github.com/gojek/courier-go/blob/main/client.go#L59)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func (c *Client) IsConnected() (online bool)\n")),(0,i.kt)("p",null,"IsConnected checks whether the client is connected to the broker"),(0,i.kt)("a",{name:"Client.Publish"}),"### func \\(\\*Client\\) [Publish](https://github.com/gojek/courier-go/blob/main/client_publish.go#L11)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func (c *Client) Publish(ctx context.Context, topic string, message interface{}, opts ...Option) error\n")),(0,i.kt)("p",null,"Publish allows to publish messages to an MQTT broker"),(0,i.kt)("a",{name:"Client.Run"}),"### func \\(\\*Client\\) [Run](https://github.com/gojek/courier-go/blob/main/client.go#L110)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func (c *Client) Run(ctx context.Context) error\n")),(0,i.kt)("p",null,"Run will start running the Client. This makes Client compatible with github.com/gojekfarm/xrun package. ",(0,i.kt)("a",{parentName:"p",href:"https://pkg.go.dev/github.com/gojekfarm/xrun"},"https://pkg.go.dev/github.com/gojekfarm/xrun")),(0,i.kt)("a",{name:"Client.Start"}),"### func \\(\\*Client\\) [Start](https://github.com/gojek/courier-go/blob/main/client.go#L68)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func (c *Client) Start() (err error)\n")),(0,i.kt)("p",null,"Start will attempt to connect to the broker."),(0,i.kt)("a",{name:"Client.Stop"}),"### func \\(\\*Client\\) [Stop](https://github.com/gojek/courier-go/blob/main/client.go#L102)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func (c *Client) Stop()\n")),(0,i.kt)("p",null,"Stop will disconnect from the broker and finish up any pending work on internal communication workers. This can only block until the period configured with the ClientOption WithGracefulShutdownPeriod."),(0,i.kt)("a",{name:"Client.Subscribe"}),"### func \\(\\*Client\\) [Subscribe](https://github.com/gojek/courier-go/blob/main/client_subscribe.go#L11)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func (c *Client) Subscribe(ctx context.Context, topic string, callback MessageHandler, opts ...Option) error\n")),(0,i.kt)("p",null,"Subscribe allows to subscribe to messages from an MQTT broker"),(0,i.kt)("a",{name:"Client.SubscribeMultiple"}),"### func \\(\\*Client\\) [SubscribeMultiple](https://github.com/gojek/courier-go/blob/main/client_subscribe.go#L16-L20)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func (c *Client) SubscribeMultiple(ctx context.Context, topicsWithQos map[string]QOSLevel, callback MessageHandler) error\n")),(0,i.kt)("p",null,"SubscribeMultiple allows to subscribe to messages on multiple topics from an MQTT broker"),(0,i.kt)("a",{name:"Client.Unsubscribe"}),"### func \\(\\*Client\\) [Unsubscribe](https://github.com/gojek/courier-go/blob/main/client_unsubscribe.go#L10)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func (c *Client) Unsubscribe(ctx context.Context, topics ...string) error\n")),(0,i.kt)("p",null,"Unsubscribe removes any subscription to messages from an MQTT broker"),(0,i.kt)("a",{name:"Client.UsePublisherMiddleware"}),"### func \\(\\*Client\\) [UsePublisherMiddleware](https://github.com/gojek/courier-go/blob/main/client_publish.go#L18)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func (c *Client) UsePublisherMiddleware(mwf ...PublisherMiddlewareFunc)\n")),(0,i.kt)("p",null,"UsePublisherMiddleware appends a PublisherMiddlewareFunc to the chain. Middleware can be used to intercept or otherwise modify, process or skip messages. They are executed in the order that they are applied to the Client."),(0,i.kt)("a",{name:"Client.UseSubscriberMiddleware"}),"### func \\(\\*Client\\) [UseSubscriberMiddleware](https://github.com/gojek/courier-go/blob/main/client_subscribe.go#L27)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func (c *Client) UseSubscriberMiddleware(mwf ...SubscriberMiddlewareFunc)\n")),(0,i.kt)("p",null,"UseSubscriberMiddleware appends a SubscriberMiddlewareFunc to the chain. Middleware can be used to intercept or otherwise modify, process or skip subscriptions. They are executed in the order that they are applied to the Client."),(0,i.kt)("a",{name:"Client.UseUnsubscriberMiddleware"}),"### func \\(\\*Client\\) [UseUnsubscriberMiddleware](https://github.com/gojek/courier-go/blob/main/client_unsubscribe.go#L17)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func (c *Client) UseUnsubscriberMiddleware(mwf ...UnsubscriberMiddlewareFunc)\n")),(0,i.kt)("p",null,"UseUnsubscriberMiddleware appends a UnsubscriberMiddlewareFunc to the chain. Middleware can be used to intercept or otherwise modify, process or skip subscriptions. They are executed in the order that they are applied to the Client."),(0,i.kt)("a",{name:"ClientOption"}),"## type [ClientOption](https://github.com/gojek/courier-go/blob/main/client_options.go#L12)",(0,i.kt)("p",null,"ClientOption allows to configure the behaviour of a Client."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type ClientOption interface {\n // contains filtered or unexported methods\n}\n")),(0,i.kt)("a",{name:"WithAddress"}),"### func [WithAddress](https://github.com/gojek/courier-go/blob/main/client_options.go#L115)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func WithAddress(host string, port uint16) ClientOption\n")),(0,i.kt)("p",null,'WithAddress sets the broker address to be used. To establish a TLS connection, use WithTLS Option along with this. Default values for hostname is "127.0.0.1" and for port is 1883.'),(0,i.kt)("a",{name:"WithAutoReconnect"}),"### func [WithAutoReconnect](https://github.com/gojek/courier-go/blob/main/client_options.go#L45)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func WithAutoReconnect(autoReconnect bool) ClientOption\n")),(0,i.kt)("p",null,"WithAutoReconnect sets whether the automatic reconnection logic should be used when the connection is lost, even if disabled the WithOnConnectionLost is still called."),(0,i.kt)("a",{name:"WithCleanSession"}),"### func [WithCleanSession](https://github.com/gojek/courier-go/blob/main/client_options.go#L57)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func WithCleanSession(cleanSession bool) ClientOption\n")),(0,i.kt)("p",null,'WithCleanSession will set the "clean session" flag in the connect message when this client connects to an MQTT broker. By setting this flag, you are indicating that no messages saved by the broker for this client should be delivered. Any messages that were going to be sent by this client before disconnecting but didn\'t, will not be sent upon connecting to the broker.'),(0,i.kt)("a",{name:"WithClientID"}),"### func [WithClientID](https://github.com/gojek/courier-go/blob/main/client_options.go#L16)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func WithClientID(clientID string) ClientOption\n")),(0,i.kt)("p",null,"WithClientID sets the clientID to be used while connecting to an MQTT broker. According to the MQTT v3.1 specification, a client id must be no longer than 23 characters."),(0,i.kt)("a",{name:"WithConnectTimeout"}),"### func [WithConnectTimeout](https://github.com/gojek/courier-go/blob/main/client_options.go#L134)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func WithConnectTimeout(duration time.Duration) ClientOption\n")),(0,i.kt)("p",null,"WithConnectTimeout limits how long the client will wait when trying to open a connection to an MQTT server before timing out. A duration of 0 never times out. Default 15 seconds."),(0,i.kt)("a",{name:"WithCustomDecoder"}),"### func [WithCustomDecoder](https://github.com/gojek/courier-go/blob/main/client_options.go#L176)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func WithCustomDecoder(decoderFunc DecoderFunc) ClientOption\n")),(0,i.kt)("p",null,"WithCustomDecoder allows to decode message bytes into the desired object."),(0,i.kt)("a",{name:"WithCustomEncoder"}),"### func [WithCustomEncoder](https://github.com/gojek/courier-go/blob/main/client_options.go#L173)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func WithCustomEncoder(encoderFunc EncoderFunc) ClientOption\n")),(0,i.kt)("p",null,"WithCustomEncoder allows to transform objects into the desired message bytes."),(0,i.kt)("a",{name:"WithExponentialStartOptions"}),"### func [WithExponentialStartOptions](https://github.com/gojek/courier-go/blob/main/client_options.go#L188)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func WithExponentialStartOptions(options ...StartOption) ClientOption\n")),(0,i.kt)("p",null,"WithExponentialStartOptions configures the client to use ExponentialStartStrategy along with the passed StartOption","(","s",")"," when using the Client.Run method."),(0,i.kt)("a",{name:"WithGracefulShutdownPeriod"}),"### func [WithGracefulShutdownPeriod](https://github.com/gojek/courier-go/blob/main/client_options.go#L158)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func WithGracefulShutdownPeriod(duration time.Duration) ClientOption\n")),(0,i.kt)("p",null,"WithGracefulShutdownPeriod sets the limit that is allowed for existing work to be completed."),(0,i.kt)("a",{name:"WithKeepAlive"}),"### func [WithKeepAlive](https://github.com/gojek/courier-go/blob/main/client_options.go#L125)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func WithKeepAlive(duration time.Duration) ClientOption\n")),(0,i.kt)("p",null,"WithKeepAlive will set the amount of time ","(","in seconds",")"," that the client should wait before sending a PING request to the broker. This will allow the client to know that a connection has not been lost with the server."),(0,i.kt)("a",{name:"WithMaintainOrder"}),"### func [WithMaintainOrder](https://github.com/gojek/courier-go/blob/main/client_options.go#L71)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func WithMaintainOrder(maintainOrder bool) ClientOption\n")),(0,i.kt)("p",null,"WithMaintainOrder will set the message routing to guarantee order within each QoS level. By default, this value is true. If set to false ","(","recommended",")",", this flag indicates that messages can be delivered asynchronously from the client to the application and possibly arrive out of order. Specifically, the message handler is called in its own go routine. Note that setting this to true does not guarantee in","-","order delivery ","(",'this is subject to broker settings like "max',"_","inflight","_",'messages=1"',")"," and if true then MessageHandler callback must not block."),(0,i.kt)("a",{name:"WithMaxReconnectInterval"}),"### func [WithMaxReconnectInterval](https://github.com/gojek/courier-go/blob/main/client_options.go#L151)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func WithMaxReconnectInterval(duration time.Duration) ClientOption\n")),(0,i.kt)("p",null,"WithMaxReconnectInterval sets the maximum time that will be waited between reconnection attempts. when connection is lost"),(0,i.kt)("a",{name:"WithOnConnect"}),"### func [WithOnConnect](https://github.com/gojek/courier-go/blob/main/client_options.go#L79)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func WithOnConnect(handler OnConnectHandler) ClientOption\n")),(0,i.kt)("p",null,"WithOnConnect will set the OnConnectHandler callback to be called when the client is connected. Both at initial connection time and upon automatic reconnect."),(0,i.kt)("a",{name:"WithOnConnectionLost"}),"### func [WithOnConnectionLost](https://github.com/gojek/courier-go/blob/main/client_options.go#L87)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func WithOnConnectionLost(handler OnConnectionLostHandler) ClientOption\n")),(0,i.kt)("p",null,"WithOnConnectionLost will set the OnConnectionLostHandler callback to be executed in the case where the client unexpectedly loses connection with the MQTT broker."),(0,i.kt)("a",{name:"WithOnReconnect"}),"### func [WithOnReconnect](https://github.com/gojek/courier-go/blob/main/client_options.go#L95)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func WithOnReconnect(handler OnReconnectHandler) ClientOption\n")),(0,i.kt)("p",null,"WithOnReconnect sets the OnReconnectHandler callback to be executed prior to the client attempting a reconnect to the MQTT broker."),(0,i.kt)("a",{name:"WithPassword"}),"### func [WithPassword](https://github.com/gojek/courier-go/blob/main/client_options.go#L30)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func WithPassword(password string) ClientOption\n")),(0,i.kt)("p",null,"WithPassword sets the password to be used while connecting to an MQTT broker."),(0,i.kt)("a",{name:"WithPersistence"}),"### func [WithPersistence](https://github.com/gojek/courier-go/blob/main/client_options.go#L166)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func WithPersistence(store Store) ClientOption\n")),(0,i.kt)("p",null,"WithPersistence allows to configure the store to be used by broker Default persistence is in","-","memory persistence with mqtt.MemoryStore"),(0,i.kt)("a",{name:"WithResolver"}),"### func [WithResolver](https://github.com/gojek/courier-go/blob/main/client_resolver.go#L25)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func WithResolver(resolver Resolver) ClientOption\n")),(0,i.kt)("p",null,"WithResolver sets the specified Resolver."),(0,i.kt)("a",{name:"WithTCPAddress"}),"### func [WithTCPAddress](https://github.com/gojek/courier-go/blob/main/client_options.go#L106)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func WithTCPAddress(host string, port uint16) ClientOption\n")),(0,i.kt)("p",null,'WithTCPAddress sets the broker address to be used. Default values for hostname is "127.0.0.1" and for port is 1883.'),(0,i.kt)("p",null,"Deprecated: This Option used to work with plain TCP connections, it's now possible to use TLS with WithAddress and WithTLS combination."),(0,i.kt)("a",{name:"WithTLS"}),"### func [WithTLS](https://github.com/gojek/courier-go/blob/main/client_options.go#L37)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func WithTLS(tlsConfig *tls.Config) ClientOption\n")),(0,i.kt)("p",null,"WithTLS sets the TLs configuration to be used while connecting to an MQTT broker."),(0,i.kt)("a",{name:"WithUseBase64Decoder"}),"### func [WithUseBase64Decoder](https://github.com/gojek/courier-go/blob/main/client_options.go#L180)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func WithUseBase64Decoder() ClientOption\n")),(0,i.kt)("p",null,"WithUseBase64Decoder configures a json decoder with a base64.StdEncoding wrapped decoder which decodes base64 encoded message bytes into the passed object."),(0,i.kt)("a",{name:"WithUsername"}),"### func [WithUsername](https://github.com/gojek/courier-go/blob/main/client_options.go#L23)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func WithUsername(username string) ClientOption\n")),(0,i.kt)("p",null,"WithUsername sets the username to be used while connecting to an MQTT broker."),(0,i.kt)("a",{name:"WithWriteTimeout"}),"### func [WithWriteTimeout](https://github.com/gojek/courier-go/blob/main/client_options.go#L143)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func WithWriteTimeout(duration time.Duration) ClientOption\n")),(0,i.kt)("p",null,"WithWriteTimeout limits how long the client will wait when trying to publish, subscribe or unsubscribe on topic when a context deadline is not set while calling Publisher.Publish, Subscriber.Subscribe, Subscriber.SubscribeMultiple or Unsubscriber.Unsubscribe."),(0,i.kt)("a",{name:"ConnectionInformer"}),"## type [ConnectionInformer](https://github.com/gojek/courier-go/blob/main/interface.go#L13-L16)",(0,i.kt)("p",null,"ConnectionInformer can be used to get information about the connection"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type ConnectionInformer interface {\n // IsConnected checks whether the client is connected to the broker\n IsConnected() bool\n}\n")),(0,i.kt)("a",{name:"Decoder"}),"## type [Decoder](https://github.com/gojek/courier-go/blob/main/decoder.go#L16-L19)",(0,i.kt)("p",null,"Decoder helps to decode message bytes into the desired object"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type Decoder interface {\n // Decode decodes message bytes into the passed object\n Decode(v interface{}) error\n}\n")),(0,i.kt)("a",{name:"DefaultDecoderFunc"}),"### func [DefaultDecoderFunc](https://github.com/gojek/courier-go/blob/main/decoder.go#L22)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func DefaultDecoderFunc(_ context.Context, r io.Reader) Decoder\n")),(0,i.kt)("p",null,"DefaultDecoderFunc is a DecoderFunc that uses a json.Decoder as the Decoder."),(0,i.kt)("a",{name:"DecoderFunc"}),"## type [DecoderFunc](https://github.com/gojek/courier-go/blob/main/decoder.go#L13)",(0,i.kt)("p",null,"DecoderFunc is used to create a Decoder from io.Reader stream of message bytes before calling MessageHandler; the context.Context value may be used to select appropriate Decoder."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type DecoderFunc func(context.Context, io.Reader) Decoder\n")),(0,i.kt)("a",{name:"Encoder"}),"## type [Encoder](https://github.com/gojek/courier-go/blob/main/encoder.go#L14-L17)",(0,i.kt)("p",null,"Encoder helps in transforming objects to message bytes"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type Encoder interface {\n // Encode takes any object and encodes it into bytes\n Encode(v interface{}) error\n}\n")),(0,i.kt)("a",{name:"DefaultEncoderFunc"}),"### func [DefaultEncoderFunc](https://github.com/gojek/courier-go/blob/main/encoder.go#L20)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func DefaultEncoderFunc(_ context.Context, w io.Writer) Encoder\n")),(0,i.kt)("p",null,"DefaultEncoderFunc is a EncoderFunc that uses a json.Encoder as the Encoder."),(0,i.kt)("a",{name:"EncoderFunc"}),"## type [EncoderFunc](https://github.com/gojek/courier-go/blob/main/encoder.go#L11)",(0,i.kt)("p",null,"EncoderFunc is used to create an Encoder from io.Writer; the context.Context value may be used to select appropriate Encoder."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type EncoderFunc func(context.Context, io.Writer) Encoder\n")),(0,i.kt)("a",{name:"Message"}),"## type [Message](https://github.com/gojek/courier-go/blob/main/message.go#L4-L12)",(0,i.kt)("p",null,"Message represents the entity that is being relayed via the courier MQTT brokers from Publisher","(","s",")"," to Subscriber","(","s",")","."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type Message struct {\n ID int\n Topic string\n Duplicate bool\n Retained bool\n QoS QOSLevel\n // contains filtered or unexported fields\n}\n")),(0,i.kt)("a",{name:"NewMessageWithDecoder"}),"### func [NewMessageWithDecoder](https://github.com/gojek/courier-go/blob/main/message.go#L15-L17)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func NewMessageWithDecoder(payloadDecoder Decoder) *Message\n")),(0,i.kt)("p",null,"NewMessageWithDecoder is a helper to create Message, ideally payloadDecoder should not be mutated once created."),(0,i.kt)("a",{name:"Message.DecodePayload"}),"### func \\(\\*Message\\) [DecodePayload](https://github.com/gojek/courier-go/blob/main/message.go#L24)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func (m *Message) DecodePayload(v interface{}) error\n")),(0,i.kt)("p",null,"DecodePayload can decode the message payload bytes into the desired object."),(0,i.kt)("a",{name:"MessageHandler"}),"## type [MessageHandler](https://github.com/gojek/courier-go/blob/main/types.go#L24)",(0,i.kt)("p",null,"MessageHandler is the type that all callbacks being passed to Subscriber must satisfy."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type MessageHandler func(context.Context, PubSub, *Message)\n")),(0,i.kt)("a",{name:"OnConnectHandler"}),"## type [OnConnectHandler](https://github.com/gojek/courier-go/blob/main/types.go#L10)",(0,i.kt)("p",null,"OnConnectHandler is a callback that is called when the client state changes from disconnected to connected. Both at initial connection and on reconnection"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type OnConnectHandler func(PubSub)\n")),(0,i.kt)("a",{name:"OnConnectionLostHandler"}),"## type [OnConnectionLostHandler](https://github.com/gojek/courier-go/blob/main/types.go#L16)",(0,i.kt)("p",null,"OnConnectionLostHandler is a callback type which can be set to be executed upon an unintended disconnection from the MQTT broker. Disconnects caused by calling Disconnect or ForceDisconnect will not cause an WithOnConnectionLost callback to execute."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type OnConnectionLostHandler func(error)\n")),(0,i.kt)("a",{name:"OnReconnectHandler"}),"## type [OnReconnectHandler](https://github.com/gojek/courier-go/blob/main/types.go#L20)",(0,i.kt)("p",null,"OnReconnectHandler is invoked prior to reconnecting after the initial connection is lost"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type OnReconnectHandler func(PubSub)\n")),(0,i.kt)("a",{name:"Option"}),"## type [Option](https://github.com/gojek/courier-go/blob/main/options.go#L4-L6)",(0,i.kt)("p",null,"Option changes behaviour of Publisher.Publish, Subscriber.Subscribe calls."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type Option interface {\n // contains filtered or unexported methods\n}\n")),(0,i.kt)("a",{name:"PubSub"}),"## type [PubSub](https://github.com/gojek/courier-go/blob/main/interface.go#L5-L10)",(0,i.kt)("p",null,"PubSub exposes all the operational functionalities of Client with Publisher, Subscriber, Unsubscriber and ConnectionInformer"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type PubSub interface {\n Publisher\n Subscriber\n Unsubscriber\n ConnectionInformer\n}\n")),(0,i.kt)("a",{name:"Publisher"}),"## type [Publisher](https://github.com/gojek/courier-go/blob/main/publisher.go#L8-L11)",(0,i.kt)("p",null,"Publisher defines behaviour of an MQTT publisher that can send messages."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type Publisher interface {\n // Publish allows to publish messages to an MQTT broker\n Publish(ctx context.Context, topic string, message interface{}, options ...Option) error\n}\n")),(0,i.kt)("a",{name:"PublisherFunc"}),"## type [PublisherFunc](https://github.com/gojek/courier-go/blob/main/publisher.go#L14)",(0,i.kt)("p",null,"PublisherFunc defines signature of a Publish function."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type PublisherFunc func(context.Context, string, interface{}, ...Option) error\n")),(0,i.kt)("a",{name:"PublisherFunc.Publish"}),"### func \\(PublisherFunc\\) [Publish](https://github.com/gojek/courier-go/blob/main/publisher.go#L17-L22)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func (f PublisherFunc) Publish(ctx context.Context, topic string, message interface{}, opts ...Option) error\n")),(0,i.kt)("p",null,"Publish implements Publisher interface on PublisherFunc."),(0,i.kt)("a",{name:"PublisherMiddlewareFunc"}),"## type [PublisherMiddlewareFunc](https://github.com/gojek/courier-go/blob/main/publisher.go#L32)",(0,i.kt)("p",null,"PublisherMiddlewareFunc functions are closures that intercept Publisher.Publish calls."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type PublisherMiddlewareFunc func(Publisher) Publisher\n")),(0,i.kt)("a",{name:"PublisherMiddlewareFunc.Middleware"}),"### func \\(PublisherMiddlewareFunc\\) [Middleware](https://github.com/gojek/courier-go/blob/main/publisher.go#L35)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func (pmw PublisherMiddlewareFunc) Middleware(publisher Publisher) Publisher\n")),(0,i.kt)("p",null,"Middleware allows PublisherMiddlewareFunc to implement the publishMiddleware interface."),(0,i.kt)("a",{name:"QOSLevel"}),"## type [QOSLevel](https://github.com/gojek/courier-go/blob/main/options.go#L10)",(0,i.kt)("p",null,"QOSLevel is an agreement between the sender of a message and the receiver of a message that defines the guarantee of delivery for a specific message"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type QOSLevel uint8\n")),(0,i.kt)("a",{name:"QOSZero"}),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"const (\n // QOSZero denotes at most once message delivery\n QOSZero QOSLevel = 0\n // QOSOne denotes at least once message delivery\n QOSOne QOSLevel = 1\n // QOSTwo denotes exactly once message delivery\n QOSTwo QOSLevel = 2\n)\n")),(0,i.kt)("a",{name:"Resolver"}),"## type [Resolver](https://github.com/gojek/courier-go/blob/main/client_resolver.go#L17-L22)",(0,i.kt)("p",null,"Resolver sends TCPAddress updates on channel returned by UpdateChan","(",")"," channel."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type Resolver interface {\n // UpdateChan returns a channel where TCPAddress updates can be received.\n UpdateChan() <-chan []TCPAddress\n // Done returns a channel which is closed when the Resolver is no longer running.\n Done() <-chan struct{}\n}\n")),(0,i.kt)("a",{name:"Retained"}),"## type [Retained](https://github.com/gojek/courier-go/blob/main/options.go#L26)",(0,i.kt)("p",null,"Retained is an option used with Publisher.Publish call"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type Retained bool\n")),(0,i.kt)("a",{name:"StartOption"}),"## type [StartOption](https://github.com/gojek/courier-go/blob/main/exp_starter.go#L9)",(0,i.kt)("p",null,"StartOption can be used to customise behaviour of ExponentialStartStrategy"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type StartOption func(*startOptions)\n")),(0,i.kt)("a",{name:"WithMaxInterval"}),"### func [WithMaxInterval](https://github.com/gojek/courier-go/blob/main/exp_starter.go#L13)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func WithMaxInterval(interval time.Duration) StartOption\n")),(0,i.kt)("p",null,"WithMaxInterval sets the maximum interval the retry logic will wait before attempting another Client.Start, Default is 30 seconds"),(0,i.kt)("a",{name:"WithOnRetry"}),"### func [WithOnRetry](https://github.com/gojek/courier-go/blob/main/exp_starter.go#L23)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func WithOnRetry(retryFunc func(error)) StartOption\n")),(0,i.kt)("p",null,"WithOnRetry sets the func which is called when there is an error in the previous Client.Start attempt"),(0,i.kt)("a",{name:"Store"}),"## type [Store](https://github.com/gojek/courier-go/blob/main/alias.go#L16)",(0,i.kt)("p",null,"Store is an interface which can be used to provide implementations for message persistence."),(0,i.kt)("p",null,"[","IMPORTANT","]"," When implementing a store with a shared storage ","(","ex: redis",")"," across multiple application instances, it should be ensured that the keys are namespaced for each application instance otherwise there will be collisions. The messages are identified based on message id from the MQTT packets, and they have values in range ","(","0, 2^16",")",", this coincides with max number of in","-","flight messages"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type Store = mqtt.Store\n")),(0,i.kt)("a",{name:"NewMemoryStore"}),"### func [NewMemoryStore](https://github.com/gojek/courier-go/blob/main/alias.go#L21)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func NewMemoryStore() Store\n")),(0,i.kt)("p",null,"NewMemoryStore returns a pointer to a new instance of mqtt.MemoryStore, the instance is not initialized and ready to use until Open","(",")"," has been called on it."),(0,i.kt)("a",{name:"Subscriber"}),"## type [Subscriber](https://github.com/gojek/courier-go/blob/main/subscriber.go#L8-L14)",(0,i.kt)("p",null,"Subscriber defines behaviour of an MQTT subscriber that can create subscriptions."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type Subscriber interface {\n // Subscribe allows to subscribe to messages from an MQTT broker\n Subscribe(ctx context.Context, topic string, callback MessageHandler, opts ...Option) error\n\n // SubscribeMultiple allows to subscribe to messages on multiple topics from an MQTT broker\n SubscribeMultiple(ctx context.Context, topicsWithQos map[string]QOSLevel, callback MessageHandler) error\n}\n")),(0,i.kt)("a",{name:"SubscriberFuncs"}),"## type [SubscriberFuncs](https://github.com/gojek/courier-go/blob/main/subscriber.go#L30-L33)",(0,i.kt)("p",null,"SubscriberFuncs defines signature of a Subscribe function."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type SubscriberFuncs struct {\n // contains filtered or unexported fields\n}\n")),(0,i.kt)("a",{name:"NewSubscriberFuncs"}),"### func [NewSubscriberFuncs](https://github.com/gojek/courier-go/blob/main/subscriber.go#L36-L39)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func NewSubscriberFuncs(subscribeFunc func(context.Context, string, MessageHandler, ...Option) error, subscribeMultipleFunc func(context.Context, map[string]QOSLevel, MessageHandler) error) SubscriberFuncs\n")),(0,i.kt)("p",null,"NewSubscriberFuncs is a helper function to create SubscriberFuncs"),(0,i.kt)("a",{name:"SubscriberFuncs.Subscribe"}),"### func \\(SubscriberFuncs\\) [Subscribe](https://github.com/gojek/courier-go/blob/main/subscriber.go#L44)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func (s SubscriberFuncs) Subscribe(ctx context.Context, topic string, callback MessageHandler, opts ...Option) error\n")),(0,i.kt)("p",null,"Subscribe implements Subscriber interface on SubscriberFuncs."),(0,i.kt)("a",{name:"SubscriberFuncs.SubscribeMultiple"}),"### func \\(SubscriberFuncs\\) [SubscribeMultiple](https://github.com/gojek/courier-go/blob/main/subscriber.go#L49-L53)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func (s SubscriberFuncs) SubscribeMultiple(ctx context.Context, topicsWithQos map[string]QOSLevel, callback MessageHandler) error\n")),(0,i.kt)("p",null,"SubscribeMultiple implements Subscriber interface on SubscriberFuncs."),(0,i.kt)("a",{name:"SubscriberMiddlewareFunc"}),"## type [SubscriberMiddlewareFunc](https://github.com/gojek/courier-go/blob/main/subscriber.go#L22)",(0,i.kt)("p",null,"SubscriberMiddlewareFunc functions are closures that intercept Subscriber.Subscribe calls."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type SubscriberMiddlewareFunc func(Subscriber) Subscriber\n")),(0,i.kt)("a",{name:"SubscriberMiddlewareFunc.Middleware"}),"### func \\(SubscriberMiddlewareFunc\\) [Middleware](https://github.com/gojek/courier-go/blob/main/subscriber.go#L25)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func (smw SubscriberMiddlewareFunc) Middleware(subscriber Subscriber) Subscriber\n")),(0,i.kt)("p",null,"Middleware allows SubscriberMiddlewareFunc to implement the subscribeMiddleware interface."),(0,i.kt)("a",{name:"TCPAddress"}),"## type [TCPAddress](https://github.com/gojek/courier-go/blob/main/client_resolver.go#L11-L14)",(0,i.kt)("p",null,"TCPAddress specifies Host and Port for remote broker"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type TCPAddress struct {\n Host string\n Port uint16\n}\n")),(0,i.kt)("a",{name:"Unsubscriber"}),"## type [Unsubscriber](https://github.com/gojek/courier-go/blob/main/unsubscriber.go#L8-L11)",(0,i.kt)("p",null,"Unsubscriber defines behaviour of an MQTT client that can remove subscriptions."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type Unsubscriber interface {\n // Unsubscribe removes any subscription to messages from an MQTT broker\n Unsubscribe(ctx context.Context, topics ...string) error\n}\n")),(0,i.kt)("a",{name:"UnsubscriberFunc"}),"## type [UnsubscriberFunc](https://github.com/gojek/courier-go/blob/main/unsubscriber.go#L27)",(0,i.kt)("p",null,"UnsubscriberFunc defines signature of a Unsubscribe function."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type UnsubscriberFunc func(context.Context, ...string) error\n")),(0,i.kt)("a",{name:"UnsubscriberFunc.Unsubscribe"}),"### func \\(UnsubscriberFunc\\) [Unsubscribe](https://github.com/gojek/courier-go/blob/main/unsubscriber.go#L30)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func (f UnsubscriberFunc) Unsubscribe(ctx context.Context, topics ...string) error\n")),(0,i.kt)("p",null,"Unsubscribe implements Unsubscriber interface on UnsubscriberFunc."),(0,i.kt)("a",{name:"UnsubscriberMiddlewareFunc"}),"## type [UnsubscriberMiddlewareFunc](https://github.com/gojek/courier-go/blob/main/unsubscriber.go#L19)",(0,i.kt)("p",null,"UnsubscriberMiddlewareFunc functions are closures that intercept Unsubscriber.Unsubscribe calls."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"type UnsubscriberMiddlewareFunc func(Unsubscriber) Unsubscriber\n")),(0,i.kt)("a",{name:"UnsubscriberMiddlewareFunc.Middleware"}),"### func \\(UnsubscriberMiddlewareFunc\\) [Middleware](https://github.com/gojek/courier-go/blob/main/unsubscriber.go#L22)",(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-go"},"func (usmw UnsubscriberMiddlewareFunc) Middleware(unsubscriber Unsubscriber) Unsubscriber\n")),(0,i.kt)("p",null,"Middleware allows UnsubscriberMiddlewareFunc to implement the unsubscribeMiddleware interface."),(0,i.kt)("p",null,"Generated by ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/princjef/gomarkdoc"},"gomarkdoc")))}b.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/0a887687.a6a0d0f0.js b/assets/js/0a887687.a6a0d0f0.js deleted file mode 100644 index d38cc90..0000000 --- a/assets/js/0a887687.a6a0d0f0.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkcourier=self.webpackChunkcourier||[]).push([[990],{3905:(e,t,n)=>{n.d(t,{Zo:()=>u,kt:()=>g});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var c=r.createContext({}),s=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},u=function(e){var t=s(e.components);return r.createElement(c.Provider,{value:t},e.children)},p="mdxType",b={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,i=e.originalType,c=e.parentName,u=l(e,["components","mdxType","originalType","parentName"]),p=s(n),m=a,g=p["".concat(c,".").concat(m)]||p[m]||b[m]||i;return n?r.createElement(g,o(o({ref:t},u),{},{components:n})):r.createElement(g,o({ref:t},u))}));function g(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var i=n.length,o=new Array(i);o[0]=m;var l={};for(var c in t)hasOwnProperty.call(t,c)&&(l[c]=t[c]);l.originalType=e,l[p]="string"==typeof e?e:a,o[1]=l;for(var s=2;s{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>o,default:()=>b,frontMatter:()=>i,metadata:()=>l,toc:()=>s});var r=n(7462),a=(n(7294),n(3905));const i={},o=void 0,l={unversionedId:"sdk/SDK",id:"sdk/SDK",title:"SDK",description:"Package courier contains the client that can be used to interact with the courier infrastructure to publish/subscribe to messages from other clients",source:"@site/docs/sdk/SDK.md",sourceDirName:"sdk",slug:"/sdk/",permalink:"/courier-go/docs/sdk/",draft:!1,editUrl:"https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/docs/sdk/SDK.md",tags:[],version:"current",frontMatter:{},sidebar:"tutorialSidebar",previous:{title:"Subscribe Messages",permalink:"/courier-go/docs/Tutorials/subscribe"},next:{title:"otelcourier",permalink:"/courier-go/docs/sdk/otelcourier"}},c={},s=[{value:"Index",id:"index",level:2},{value:"Variables",id:"variables",level:2}],u={toc:s},p="wrapper";function b(e){let{components:t,...n}=e;return(0,a.kt)(p,(0,r.Z)({},u,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("h1",{id:"courier"},"courier"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},'import "github.com/gojek/courier-go"\n')),(0,a.kt)("p",null,"Package courier contains the client that can be used to interact with the courier infrastructure to publish/subscribe to messages from other clients"),(0,a.kt)("h2",{id:"index"},"Index"),(0,a.kt)("ul",null,(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#variables"},"Variables")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#ExponentialStartStrategy"},"func ExponentialStartStrategy","(","ctx context.Context, c interface","{"," Start","(",")"," error ","}",", opts ...StartOption",")")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#Version"},"func Version","(",")"," string")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#WaitForConnection"},"func WaitForConnection","(","c ConnectionInformer, waitFor time.Duration, tick time.Duration",")"," bool")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#Client"},"type Client"),(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#NewClient"},"func NewClient","(","opts ...ClientOption",")"," ","(","*","Client, error",")")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#Client.IsConnected"},"func ","(","c ","*","Client",")"," IsConnected","(",")"," ","(","online bool",")")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#Client.Publish"},"func ","(","c ","*","Client",")"," Publish","(","ctx context.Context, topic string, message interface","{","}",", opts ...Option",")"," error")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#Client.Run"},"func ","(","c ","*","Client",")"," Run","(","ctx context.Context",")"," error")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#Client.Start"},"func ","(","c ","*","Client",")"," Start","(",")"," ","(","err error",")")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#Client.Stop"},"func ","(","c ","*","Client",")"," Stop","(",")")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#Client.Subscribe"},"func ","(","c ","*","Client",")"," Subscribe","(","ctx context.Context, topic string, callback MessageHandler, opts ...Option",")"," error")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#Client.SubscribeMultiple"},"func ","(","c ","*","Client",")"," SubscribeMultiple","(","ctx context.Context, topicsWithQos map","[","string","]","QOSLevel, callback MessageHandler",")"," error")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#Client.Unsubscribe"},"func ","(","c ","*","Client",")"," Unsubscribe","(","ctx context.Context, topics ...string",")"," error")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#Client.UsePublisherMiddleware"},"func ","(","c ","*","Client",")"," UsePublisherMiddleware","(","mwf ...PublisherMiddlewareFunc",")")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#Client.UseSubscriberMiddleware"},"func ","(","c ","*","Client",")"," UseSubscriberMiddleware","(","mwf ...SubscriberMiddlewareFunc",")")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#Client.UseUnsubscriberMiddleware"},"func ","(","c ","*","Client",")"," UseUnsubscriberMiddleware","(","mwf ...UnsubscriberMiddlewareFunc",")")))),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#ClientOption"},"type ClientOption"),(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#WithAddress"},"func WithAddress","(","host string, port uint16",")"," ClientOption")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#WithAutoReconnect"},"func WithAutoReconnect","(","autoReconnect bool",")"," ClientOption")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#WithCleanSession"},"func WithCleanSession","(","cleanSession bool",")"," ClientOption")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#WithClientID"},"func WithClientID","(","clientID string",")"," ClientOption")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#WithConnectTimeout"},"func WithConnectTimeout","(","duration time.Duration",")"," ClientOption")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#WithCustomDecoder"},"func WithCustomDecoder","(","decoderFunc DecoderFunc",")"," ClientOption")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#WithCustomEncoder"},"func WithCustomEncoder","(","encoderFunc EncoderFunc",")"," ClientOption")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#WithGracefulShutdownPeriod"},"func WithGracefulShutdownPeriod","(","duration time.Duration",")"," ClientOption")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#WithKeepAlive"},"func WithKeepAlive","(","duration time.Duration",")"," ClientOption")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#WithMaintainOrder"},"func WithMaintainOrder","(","maintainOrder bool",")"," ClientOption")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#WithMaxReconnectInterval"},"func WithMaxReconnectInterval","(","duration time.Duration",")"," ClientOption")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#WithOnConnect"},"func WithOnConnect","(","handler OnConnectHandler",")"," ClientOption")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#WithOnConnectionLost"},"func WithOnConnectionLost","(","handler OnConnectionLostHandler",")"," ClientOption")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#WithOnReconnect"},"func WithOnReconnect","(","handler OnReconnectHandler",")"," ClientOption")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#WithPassword"},"func WithPassword","(","password string",")"," ClientOption")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#WithPersistence"},"func WithPersistence","(","store Store",")"," ClientOption")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#WithResolver"},"func WithResolver","(","resolver Resolver",")"," ClientOption")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#WithTCPAddress"},"func WithTCPAddress","(","host string, port uint16",")"," ClientOption")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#WithTLS"},"func WithTLS","(","tlsConfig ","*","tls.Config",")"," ClientOption")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#WithUseBase64Decoder"},"func WithUseBase64Decoder","(",")"," ClientOption")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#WithUsername"},"func WithUsername","(","username string",")"," ClientOption")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#WithWriteTimeout"},"func WithWriteTimeout","(","duration time.Duration",")"," ClientOption")))),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#ConnectionInformer"},"type ConnectionInformer")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#Decoder"},"type Decoder"),(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#DefaultDecoderFunc"},"func DefaultDecoderFunc","(","_"," context.Context, r io.Reader",")"," Decoder")))),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#DecoderFunc"},"type DecoderFunc")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#Encoder"},"type Encoder"),(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#DefaultEncoderFunc"},"func DefaultEncoderFunc","(","_"," context.Context, w io.Writer",")"," Encoder")))),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#EncoderFunc"},"type EncoderFunc")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#Message"},"type Message"),(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#NewMessageWithDecoder"},"func NewMessageWithDecoder","(","payloadDecoder Decoder",")"," ","*","Message")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#Message.DecodePayload"},"func ","(","m ","*","Message",")"," DecodePayload","(","v interface","{","}",")"," error")))),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#MessageHandler"},"type MessageHandler")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#OnConnectHandler"},"type OnConnectHandler")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#OnConnectionLostHandler"},"type OnConnectionLostHandler")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#OnReconnectHandler"},"type OnReconnectHandler")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#Option"},"type Option")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#PubSub"},"type PubSub")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#Publisher"},"type Publisher")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#PublisherFunc"},"type PublisherFunc"),(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#PublisherFunc.Publish"},"func ","(","f PublisherFunc",")"," Publish","(","ctx context.Context, topic string, message interface","{","}",", opts ...Option",")"," error")))),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#PublisherMiddlewareFunc"},"type PublisherMiddlewareFunc"),(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#PublisherMiddlewareFunc.Middleware"},"func ","(","pmw PublisherMiddlewareFunc",")"," Middleware","(","publisher Publisher",")"," Publisher")))),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#QOSLevel"},"type QOSLevel")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#Resolver"},"type Resolver")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#Retained"},"type Retained")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#StartOption"},"type StartOption"),(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#WithMaxInterval"},"func WithMaxInterval","(","interval time.Duration",")"," StartOption")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#WithOnRetry"},"func WithOnRetry","(","retryFunc func","(","error",")",")"," StartOption")))),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#Store"},"type Store"),(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#NewMemoryStore"},"func NewMemoryStore","(",")"," Store")))),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#Subscriber"},"type Subscriber")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#SubscriberFuncs"},"type SubscriberFuncs"),(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#NewSubscriberFuncs"},"func NewSubscriberFuncs","(","subscribeFunc func","(","context.Context, string, MessageHandler, ...Option",")"," error, subscribeMultipleFunc func","(","context.Context, map","[","string","]","QOSLevel, MessageHandler",")"," error",")"," SubscriberFuncs")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#SubscriberFuncs.Subscribe"},"func ","(","s SubscriberFuncs",")"," Subscribe","(","ctx context.Context, topic string, callback MessageHandler, opts ...Option",")"," error")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#SubscriberFuncs.SubscribeMultiple"},"func ","(","s SubscriberFuncs",")"," SubscribeMultiple","(","ctx context.Context, topicsWithQos map","[","string","]","QOSLevel, callback MessageHandler",")"," error")))),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#SubscriberMiddlewareFunc"},"type SubscriberMiddlewareFunc"),(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#SubscriberMiddlewareFunc.Middleware"},"func ","(","smw SubscriberMiddlewareFunc",")"," Middleware","(","subscriber Subscriber",")"," Subscriber")))),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#TCPAddress"},"type TCPAddress")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#Unsubscriber"},"type Unsubscriber")),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#UnsubscriberFunc"},"type UnsubscriberFunc"),(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#UnsubscriberFunc.Unsubscribe"},"func ","(","f UnsubscriberFunc",")"," Unsubscribe","(","ctx context.Context, topics ...string",")"," error")))),(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#UnsubscriberMiddlewareFunc"},"type UnsubscriberMiddlewareFunc"),(0,a.kt)("ul",{parentName:"li"},(0,a.kt)("li",{parentName:"ul"},(0,a.kt)("a",{parentName:"li",href:"#UnsubscriberMiddlewareFunc.Middleware"},"func ","(","usmw UnsubscriberMiddlewareFunc",")"," Middleware","(","unsubscriber Unsubscriber",")"," Unsubscriber"))))),(0,a.kt)("h2",{id:"variables"},"Variables"),(0,a.kt)("a",{name:"ErrConnectTimeout"}),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},'var (\n // ErrConnectTimeout indicates connection timeout while connecting to broker.\n ErrConnectTimeout = errors.New("client timed out while trying to connect to the broker")\n // ErrPublishTimeout indicates publish timeout.\n ErrPublishTimeout = errors.New("publish timeout")\n // ErrSubscribeTimeout indicates subscribe timeout.\n ErrSubscribeTimeout = errors.New("subscribe timeout")\n // ErrUnsubscribeTimeout indicates unsubscribe timeout.\n ErrUnsubscribeTimeout = errors.New("unsubscribe timeout")\n // ErrSubscribeMultipleTimeout indicates multiple subscribe timeout.\n ErrSubscribeMultipleTimeout = errors.New("subscribe multiple timeout")\n)\n')),(0,a.kt)("a",{name:"ExponentialStartStrategy"}),"## func [ExponentialStartStrategy](https://github.com/gojek/courier-go/blob/main/exp_starter.go#L37)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func ExponentialStartStrategy(ctx context.Context, c interface{ Start() error }, opts ...StartOption)\n")),(0,a.kt)("p",null,"ExponentialStartStrategy will keep attempting to call Client.Start in the background and retry on error, it will never exit unless the context used to invoke is cancelled. This will NOT stop the client, that is the responsibility of caller."),(0,a.kt)("a",{name:"Version"}),"## func [Version](https://github.com/gojek/courier-go/blob/main/version.go#L4)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func Version() string\n")),(0,a.kt)("p",null,"Version can be used to get the current courier library version"),(0,a.kt)("a",{name:"WaitForConnection"}),"## func [WaitForConnection](https://github.com/gojek/courier-go/blob/main/utils.go#L10)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func WaitForConnection(c ConnectionInformer, waitFor time.Duration, tick time.Duration) bool\n")),(0,a.kt)("p",null,"WaitForConnection checks if the Client is connected, it calls ConnectionInformer.IsConnected after every tick and waitFor is the maximum duration it can block. Returns true only when ConnectionInformer.IsConnected returns true"),(0,a.kt)("a",{name:"Client"}),"## type [Client](https://github.com/gojek/courier-go/blob/main/client.go#L17-L29)",(0,a.kt)("p",null,"Client allows to communicate with an MQTT broker"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type Client struct {\n // contains filtered or unexported fields\n}\n")),(0,a.kt)("a",{name:"NewClient"}),"### func [NewClient](https://github.com/gojek/courier-go/blob/main/client.go#L34)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func NewClient(opts ...ClientOption) (*Client, error)\n")),(0,a.kt)("p",null,"NewClient creates the Client struct with the clientOptions provided, it can return error when prometheus.DefaultRegisterer has already been used to register the collected metrics"),(0,a.kt)("details",null,(0,a.kt)("summary",null,"Example"),(0,a.kt)("p",null,(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},'c, err := courier.NewClient(\n courier.WithUsername("username"),\n courier.WithPassword("password"),\n courier.WithAddress("localhost", 1883),\n)\n\nif err != nil {\n panic(err)\n}\n\nif err := c.Start(); err != nil {\n panic(err)\n}\n\nstopCh := make(chan os.Signal, 1)\nsignal.Notify(stopCh, []os.Signal{os.Interrupt, syscall.SIGTERM}...)\n\ngo func() {\n tick := time.NewTicker(time.Second)\n for {\n select {\n case t := <-tick.C:\n msg := map[string]interface{}{\n "time": t.UnixNano(),\n }\n if err := c.Publish(context.Background(), "topic", msg, courier.QOSOne); err != nil {\n fmt.Printf("Publish() error = %s\\n", err)\n } else {\n fmt.Println("Publish() success")\n }\n case <-stopCh:\n tick.Stop()\n return\n }\n }\n}()\n\n<-stopCh\nc.Stop()\n')))),(0,a.kt)("a",{name:"Client.IsConnected"}),"### func \\(\\*Client\\) [IsConnected](https://github.com/gojek/courier-go/blob/main/client.go#L59)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func (c *Client) IsConnected() (online bool)\n")),(0,a.kt)("p",null,"IsConnected checks whether the client is connected to the broker"),(0,a.kt)("a",{name:"Client.Publish"}),"### func \\(\\*Client\\) [Publish](https://github.com/gojek/courier-go/blob/main/client_publish.go#L11)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func (c *Client) Publish(ctx context.Context, topic string, message interface{}, opts ...Option) error\n")),(0,a.kt)("p",null,"Publish allows to publish messages to an MQTT broker"),(0,a.kt)("a",{name:"Client.Run"}),"### func \\(\\*Client\\) [Run](https://github.com/gojek/courier-go/blob/main/client.go#L110)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func (c *Client) Run(ctx context.Context) error\n")),(0,a.kt)("p",null,"Run will start running the Client. This makes Client compatible with github.com/gojekfarm/xrun package. ",(0,a.kt)("a",{parentName:"p",href:"https://pkg.go.dev/github.com/gojekfarm/xrun"},"https://pkg.go.dev/github.com/gojekfarm/xrun")),(0,a.kt)("a",{name:"Client.Start"}),"### func \\(\\*Client\\) [Start](https://github.com/gojek/courier-go/blob/main/client.go#L68)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func (c *Client) Start() (err error)\n")),(0,a.kt)("p",null,"Start will attempt to connect to the broker."),(0,a.kt)("a",{name:"Client.Stop"}),"### func \\(\\*Client\\) [Stop](https://github.com/gojek/courier-go/blob/main/client.go#L102)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func (c *Client) Stop()\n")),(0,a.kt)("p",null,"Stop will disconnect from the broker and finish up any pending work on internal communication workers. This can only block until the period configured with the ClientOption WithGracefulShutdownPeriod."),(0,a.kt)("a",{name:"Client.Subscribe"}),"### func \\(\\*Client\\) [Subscribe](https://github.com/gojek/courier-go/blob/main/client_subscribe.go#L11)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func (c *Client) Subscribe(ctx context.Context, topic string, callback MessageHandler, opts ...Option) error\n")),(0,a.kt)("p",null,"Subscribe allows to subscribe to messages from an MQTT broker"),(0,a.kt)("a",{name:"Client.SubscribeMultiple"}),"### func \\(\\*Client\\) [SubscribeMultiple](https://github.com/gojek/courier-go/blob/main/client_subscribe.go#L16-L20)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func (c *Client) SubscribeMultiple(ctx context.Context, topicsWithQos map[string]QOSLevel, callback MessageHandler) error\n")),(0,a.kt)("p",null,"SubscribeMultiple allows to subscribe to messages on multiple topics from an MQTT broker"),(0,a.kt)("a",{name:"Client.Unsubscribe"}),"### func \\(\\*Client\\) [Unsubscribe](https://github.com/gojek/courier-go/blob/main/client_unsubscribe.go#L10)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func (c *Client) Unsubscribe(ctx context.Context, topics ...string) error\n")),(0,a.kt)("p",null,"Unsubscribe removes any subscription to messages from an MQTT broker"),(0,a.kt)("a",{name:"Client.UsePublisherMiddleware"}),"### func \\(\\*Client\\) [UsePublisherMiddleware](https://github.com/gojek/courier-go/blob/main/client_publish.go#L18)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func (c *Client) UsePublisherMiddleware(mwf ...PublisherMiddlewareFunc)\n")),(0,a.kt)("p",null,"UsePublisherMiddleware appends a PublisherMiddlewareFunc to the chain. Middleware can be used to intercept or otherwise modify, process or skip messages. They are executed in the order that they are applied to the Client."),(0,a.kt)("a",{name:"Client.UseSubscriberMiddleware"}),"### func \\(\\*Client\\) [UseSubscriberMiddleware](https://github.com/gojek/courier-go/blob/main/client_subscribe.go#L27)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func (c *Client) UseSubscriberMiddleware(mwf ...SubscriberMiddlewareFunc)\n")),(0,a.kt)("p",null,"UseSubscriberMiddleware appends a SubscriberMiddlewareFunc to the chain. Middleware can be used to intercept or otherwise modify, process or skip subscriptions. They are executed in the order that they are applied to the Client."),(0,a.kt)("a",{name:"Client.UseUnsubscriberMiddleware"}),"### func \\(\\*Client\\) [UseUnsubscriberMiddleware](https://github.com/gojek/courier-go/blob/main/client_unsubscribe.go#L17)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func (c *Client) UseUnsubscriberMiddleware(mwf ...UnsubscriberMiddlewareFunc)\n")),(0,a.kt)("p",null,"UseUnsubscriberMiddleware appends a UnsubscriberMiddlewareFunc to the chain. Middleware can be used to intercept or otherwise modify, process or skip subscriptions. They are executed in the order that they are applied to the Client."),(0,a.kt)("a",{name:"ClientOption"}),"## type [ClientOption](https://github.com/gojek/courier-go/blob/main/client_options.go#L12)",(0,a.kt)("p",null,"ClientOption allows to configure the behaviour of a Client."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type ClientOption interface {\n // contains filtered or unexported methods\n}\n")),(0,a.kt)("a",{name:"WithAddress"}),"### func [WithAddress](https://github.com/gojek/courier-go/blob/main/client_options.go#L115)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func WithAddress(host string, port uint16) ClientOption\n")),(0,a.kt)("p",null,'WithAddress sets the broker address to be used. To establish a TLS connection, use WithTLS Option along with this. Default values for hostname is "127.0.0.1" and for port is 1883.'),(0,a.kt)("a",{name:"WithAutoReconnect"}),"### func [WithAutoReconnect](https://github.com/gojek/courier-go/blob/main/client_options.go#L45)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func WithAutoReconnect(autoReconnect bool) ClientOption\n")),(0,a.kt)("p",null,"WithAutoReconnect sets whether the automatic reconnection logic should be used when the connection is lost, even if disabled the WithOnConnectionLost is still called."),(0,a.kt)("a",{name:"WithCleanSession"}),"### func [WithCleanSession](https://github.com/gojek/courier-go/blob/main/client_options.go#L57)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func WithCleanSession(cleanSession bool) ClientOption\n")),(0,a.kt)("p",null,'WithCleanSession will set the "clean session" flag in the connect message when this client connects to an MQTT broker. By setting this flag, you are indicating that no messages saved by the broker for this client should be delivered. Any messages that were going to be sent by this client before disconnecting but didn\'t, will not be sent upon connecting to the broker.'),(0,a.kt)("a",{name:"WithClientID"}),"### func [WithClientID](https://github.com/gojek/courier-go/blob/main/client_options.go#L16)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func WithClientID(clientID string) ClientOption\n")),(0,a.kt)("p",null,"WithClientID sets the clientID to be used while connecting to an MQTT broker. According to the MQTT v3.1 specification, a client id must be no longer than 23 characters."),(0,a.kt)("a",{name:"WithConnectTimeout"}),"### func [WithConnectTimeout](https://github.com/gojek/courier-go/blob/main/client_options.go#L134)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func WithConnectTimeout(duration time.Duration) ClientOption\n")),(0,a.kt)("p",null,"WithConnectTimeout limits how long the client will wait when trying to open a connection to an MQTT server before timing out. A duration of 0 never times out. Default 15 seconds."),(0,a.kt)("a",{name:"WithCustomDecoder"}),"### func [WithCustomDecoder](https://github.com/gojek/courier-go/blob/main/client_options.go#L176)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func WithCustomDecoder(decoderFunc DecoderFunc) ClientOption\n")),(0,a.kt)("p",null,"WithCustomDecoder allows to decode message bytes into the desired object."),(0,a.kt)("a",{name:"WithCustomEncoder"}),"### func [WithCustomEncoder](https://github.com/gojek/courier-go/blob/main/client_options.go#L173)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func WithCustomEncoder(encoderFunc EncoderFunc) ClientOption\n")),(0,a.kt)("p",null,"WithCustomEncoder allows to transform objects into the desired message bytes."),(0,a.kt)("a",{name:"WithGracefulShutdownPeriod"}),"### func [WithGracefulShutdownPeriod](https://github.com/gojek/courier-go/blob/main/client_options.go#L158)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func WithGracefulShutdownPeriod(duration time.Duration) ClientOption\n")),(0,a.kt)("p",null,"WithGracefulShutdownPeriod sets the limit that is allowed for existing work to be completed."),(0,a.kt)("a",{name:"WithKeepAlive"}),"### func [WithKeepAlive](https://github.com/gojek/courier-go/blob/main/client_options.go#L125)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func WithKeepAlive(duration time.Duration) ClientOption\n")),(0,a.kt)("p",null,"WithKeepAlive will set the amount of time ","(","in seconds",")"," that the client should wait before sending a PING request to the broker. This will allow the client to know that a connection has not been lost with the server."),(0,a.kt)("a",{name:"WithMaintainOrder"}),"### func [WithMaintainOrder](https://github.com/gojek/courier-go/blob/main/client_options.go#L71)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func WithMaintainOrder(maintainOrder bool) ClientOption\n")),(0,a.kt)("p",null,"WithMaintainOrder will set the message routing to guarantee order within each QoS level. By default, this value is true. If set to false ","(","recommended",")",", this flag indicates that messages can be delivered asynchronously from the client to the application and possibly arrive out of order. Specifically, the message handler is called in its own go routine. Note that setting this to true does not guarantee in","-","order delivery ","(",'this is subject to broker settings like "max',"_","inflight","_",'messages=1"',")"," and if true then MessageHandler callback must not block."),(0,a.kt)("a",{name:"WithMaxReconnectInterval"}),"### func [WithMaxReconnectInterval](https://github.com/gojek/courier-go/blob/main/client_options.go#L151)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func WithMaxReconnectInterval(duration time.Duration) ClientOption\n")),(0,a.kt)("p",null,"WithMaxReconnectInterval sets the maximum time that will be waited between reconnection attempts. when connection is lost"),(0,a.kt)("a",{name:"WithOnConnect"}),"### func [WithOnConnect](https://github.com/gojek/courier-go/blob/main/client_options.go#L79)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func WithOnConnect(handler OnConnectHandler) ClientOption\n")),(0,a.kt)("p",null,"WithOnConnect will set the OnConnectHandler callback to be called when the client is connected. Both at initial connection time and upon automatic reconnect."),(0,a.kt)("a",{name:"WithOnConnectionLost"}),"### func [WithOnConnectionLost](https://github.com/gojek/courier-go/blob/main/client_options.go#L87)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func WithOnConnectionLost(handler OnConnectionLostHandler) ClientOption\n")),(0,a.kt)("p",null,"WithOnConnectionLost will set the OnConnectionLostHandler callback to be executed in the case where the client unexpectedly loses connection with the MQTT broker."),(0,a.kt)("a",{name:"WithOnReconnect"}),"### func [WithOnReconnect](https://github.com/gojek/courier-go/blob/main/client_options.go#L95)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func WithOnReconnect(handler OnReconnectHandler) ClientOption\n")),(0,a.kt)("p",null,"WithOnReconnect sets the OnReconnectHandler callback to be executed prior to the client attempting a reconnect to the MQTT broker."),(0,a.kt)("a",{name:"WithPassword"}),"### func [WithPassword](https://github.com/gojek/courier-go/blob/main/client_options.go#L30)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func WithPassword(password string) ClientOption\n")),(0,a.kt)("p",null,"WithPassword sets the password to be used while connecting to an MQTT broker."),(0,a.kt)("a",{name:"WithPersistence"}),"### func [WithPersistence](https://github.com/gojek/courier-go/blob/main/client_options.go#L166)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func WithPersistence(store Store) ClientOption\n")),(0,a.kt)("p",null,"WithPersistence allows to configure the store to be used by broker Default persistence is in","-","memory persistence with mqtt.MemoryStore"),(0,a.kt)("a",{name:"WithResolver"}),"### func [WithResolver](https://github.com/gojek/courier-go/blob/main/client_resolver.go#L25)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func WithResolver(resolver Resolver) ClientOption\n")),(0,a.kt)("p",null,"WithResolver sets the specified Resolver."),(0,a.kt)("a",{name:"WithTCPAddress"}),"### func [WithTCPAddress](https://github.com/gojek/courier-go/blob/main/client_options.go#L106)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func WithTCPAddress(host string, port uint16) ClientOption\n")),(0,a.kt)("p",null,'WithTCPAddress sets the broker address to be used. Default values for hostname is "127.0.0.1" and for port is 1883.'),(0,a.kt)("p",null,"Deprecated: This Option used to work with plain TCP connections, it's now possible to use TLS with WithAddress and WithTLS combination."),(0,a.kt)("a",{name:"WithTLS"}),"### func [WithTLS](https://github.com/gojek/courier-go/blob/main/client_options.go#L37)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func WithTLS(tlsConfig *tls.Config) ClientOption\n")),(0,a.kt)("p",null,"WithTLS sets the TLs configuration to be used while connecting to an MQTT broker."),(0,a.kt)("a",{name:"WithUseBase64Decoder"}),"### func [WithUseBase64Decoder](https://github.com/gojek/courier-go/blob/main/client_options.go#L180)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func WithUseBase64Decoder() ClientOption\n")),(0,a.kt)("p",null,"WithUseBase64Decoder configures a json decoder with a base64.StdEncoding wrapped decoder which decodes base64 encoded message bytes into the passed object."),(0,a.kt)("a",{name:"WithUsername"}),"### func [WithUsername](https://github.com/gojek/courier-go/blob/main/client_options.go#L23)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func WithUsername(username string) ClientOption\n")),(0,a.kt)("p",null,"WithUsername sets the username to be used while connecting to an MQTT broker."),(0,a.kt)("a",{name:"WithWriteTimeout"}),"### func [WithWriteTimeout](https://github.com/gojek/courier-go/blob/main/client_options.go#L143)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func WithWriteTimeout(duration time.Duration) ClientOption\n")),(0,a.kt)("p",null,"WithWriteTimeout limits how long the client will wait when trying to publish, subscribe or unsubscribe on topic when a context deadline is not set while calling Publisher.Publish, Subscriber.Subscribe, Subscriber.SubscribeMultiple or Unsubscriber.Unsubscribe."),(0,a.kt)("a",{name:"ConnectionInformer"}),"## type [ConnectionInformer](https://github.com/gojek/courier-go/blob/main/interface.go#L13-L16)",(0,a.kt)("p",null,"ConnectionInformer can be used to get information about the connection"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type ConnectionInformer interface {\n // IsConnected checks whether the client is connected to the broker\n IsConnected() bool\n}\n")),(0,a.kt)("a",{name:"Decoder"}),"## type [Decoder](https://github.com/gojek/courier-go/blob/main/decoder.go#L16-L19)",(0,a.kt)("p",null,"Decoder helps to decode message bytes into the desired object"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type Decoder interface {\n // Decode decodes message bytes into the passed object\n Decode(v interface{}) error\n}\n")),(0,a.kt)("a",{name:"DefaultDecoderFunc"}),"### func [DefaultDecoderFunc](https://github.com/gojek/courier-go/blob/main/decoder.go#L22)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func DefaultDecoderFunc(_ context.Context, r io.Reader) Decoder\n")),(0,a.kt)("p",null,"DefaultDecoderFunc is a DecoderFunc that uses a json.Decoder as the Decoder."),(0,a.kt)("a",{name:"DecoderFunc"}),"## type [DecoderFunc](https://github.com/gojek/courier-go/blob/main/decoder.go#L13)",(0,a.kt)("p",null,"DecoderFunc is used to create a Decoder from io.Reader stream of message bytes before calling MessageHandler; the context.Context value may be used to select appropriate Decoder."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type DecoderFunc func(context.Context, io.Reader) Decoder\n")),(0,a.kt)("a",{name:"Encoder"}),"## type [Encoder](https://github.com/gojek/courier-go/blob/main/encoder.go#L14-L17)",(0,a.kt)("p",null,"Encoder helps in transforming objects to message bytes"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type Encoder interface {\n // Encode takes any object and encodes it into bytes\n Encode(v interface{}) error\n}\n")),(0,a.kt)("a",{name:"DefaultEncoderFunc"}),"### func [DefaultEncoderFunc](https://github.com/gojek/courier-go/blob/main/encoder.go#L20)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func DefaultEncoderFunc(_ context.Context, w io.Writer) Encoder\n")),(0,a.kt)("p",null,"DefaultEncoderFunc is a EncoderFunc that uses a json.Encoder as the Encoder."),(0,a.kt)("a",{name:"EncoderFunc"}),"## type [EncoderFunc](https://github.com/gojek/courier-go/blob/main/encoder.go#L11)",(0,a.kt)("p",null,"EncoderFunc is used to create an Encoder from io.Writer; the context.Context value may be used to select appropriate Encoder."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type EncoderFunc func(context.Context, io.Writer) Encoder\n")),(0,a.kt)("a",{name:"Message"}),"## type [Message](https://github.com/gojek/courier-go/blob/main/message.go#L4-L12)",(0,a.kt)("p",null,"Message represents the entity that is being relayed via the courier MQTT brokers from Publisher","(","s",")"," to Subscriber","(","s",")","."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type Message struct {\n ID int\n Topic string\n Duplicate bool\n Retained bool\n QoS QOSLevel\n // contains filtered or unexported fields\n}\n")),(0,a.kt)("a",{name:"NewMessageWithDecoder"}),"### func [NewMessageWithDecoder](https://github.com/gojek/courier-go/blob/main/message.go#L15-L17)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func NewMessageWithDecoder(payloadDecoder Decoder) *Message\n")),(0,a.kt)("p",null,"NewMessageWithDecoder is a helper to create Message, ideally payloadDecoder should not be mutated once created."),(0,a.kt)("a",{name:"Message.DecodePayload"}),"### func \\(\\*Message\\) [DecodePayload](https://github.com/gojek/courier-go/blob/main/message.go#L24)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func (m *Message) DecodePayload(v interface{}) error\n")),(0,a.kt)("p",null,"DecodePayload can decode the message payload bytes into the desired object."),(0,a.kt)("a",{name:"MessageHandler"}),"## type [MessageHandler](https://github.com/gojek/courier-go/blob/main/types.go#L24)",(0,a.kt)("p",null,"MessageHandler is the type that all callbacks being passed to Subscriber must satisfy."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type MessageHandler func(context.Context, PubSub, *Message)\n")),(0,a.kt)("a",{name:"OnConnectHandler"}),"## type [OnConnectHandler](https://github.com/gojek/courier-go/blob/main/types.go#L10)",(0,a.kt)("p",null,"OnConnectHandler is a callback that is called when the client state changes from disconnected to connected. Both at initial connection and on reconnection"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type OnConnectHandler func(PubSub)\n")),(0,a.kt)("a",{name:"OnConnectionLostHandler"}),"## type [OnConnectionLostHandler](https://github.com/gojek/courier-go/blob/main/types.go#L16)",(0,a.kt)("p",null,"OnConnectionLostHandler is a callback type which can be set to be executed upon an unintended disconnection from the MQTT broker. Disconnects caused by calling Disconnect or ForceDisconnect will not cause an WithOnConnectionLost callback to execute."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type OnConnectionLostHandler func(error)\n")),(0,a.kt)("a",{name:"OnReconnectHandler"}),"## type [OnReconnectHandler](https://github.com/gojek/courier-go/blob/main/types.go#L20)",(0,a.kt)("p",null,"OnReconnectHandler is invoked prior to reconnecting after the initial connection is lost"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type OnReconnectHandler func(PubSub)\n")),(0,a.kt)("a",{name:"Option"}),"## type [Option](https://github.com/gojek/courier-go/blob/main/options.go#L4-L6)",(0,a.kt)("p",null,"Option changes behaviour of Publisher.Publish, Subscriber.Subscribe calls."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type Option interface {\n // contains filtered or unexported methods\n}\n")),(0,a.kt)("a",{name:"PubSub"}),"## type [PubSub](https://github.com/gojek/courier-go/blob/main/interface.go#L5-L10)",(0,a.kt)("p",null,"PubSub exposes all the operational functionalities of Client with Publisher, Subscriber, Unsubscriber and ConnectionInformer"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type PubSub interface {\n Publisher\n Subscriber\n Unsubscriber\n ConnectionInformer\n}\n")),(0,a.kt)("a",{name:"Publisher"}),"## type [Publisher](https://github.com/gojek/courier-go/blob/main/publisher.go#L8-L11)",(0,a.kt)("p",null,"Publisher defines behaviour of an MQTT publisher that can send messages."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type Publisher interface {\n // Publish allows to publish messages to an MQTT broker\n Publish(ctx context.Context, topic string, message interface{}, options ...Option) error\n}\n")),(0,a.kt)("a",{name:"PublisherFunc"}),"## type [PublisherFunc](https://github.com/gojek/courier-go/blob/main/publisher.go#L14)",(0,a.kt)("p",null,"PublisherFunc defines signature of a Publish function."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type PublisherFunc func(context.Context, string, interface{}, ...Option) error\n")),(0,a.kt)("a",{name:"PublisherFunc.Publish"}),"### func \\(PublisherFunc\\) [Publish](https://github.com/gojek/courier-go/blob/main/publisher.go#L17-L22)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func (f PublisherFunc) Publish(ctx context.Context, topic string, message interface{}, opts ...Option) error\n")),(0,a.kt)("p",null,"Publish implements Publisher interface on PublisherFunc."),(0,a.kt)("a",{name:"PublisherMiddlewareFunc"}),"## type [PublisherMiddlewareFunc](https://github.com/gojek/courier-go/blob/main/publisher.go#L32)",(0,a.kt)("p",null,"PublisherMiddlewareFunc functions are closures that intercept Publisher.Publish calls."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type PublisherMiddlewareFunc func(Publisher) Publisher\n")),(0,a.kt)("a",{name:"PublisherMiddlewareFunc.Middleware"}),"### func \\(PublisherMiddlewareFunc\\) [Middleware](https://github.com/gojek/courier-go/blob/main/publisher.go#L35)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func (pmw PublisherMiddlewareFunc) Middleware(publisher Publisher) Publisher\n")),(0,a.kt)("p",null,"Middleware allows PublisherMiddlewareFunc to implement the publishMiddleware interface."),(0,a.kt)("a",{name:"QOSLevel"}),"## type [QOSLevel](https://github.com/gojek/courier-go/blob/main/options.go#L10)",(0,a.kt)("p",null,"QOSLevel is an agreement between the sender of a message and the receiver of a message that defines the guarantee of delivery for a specific message"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type QOSLevel uint8\n")),(0,a.kt)("a",{name:"QOSZero"}),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"const (\n // QOSZero denotes at most once message delivery\n QOSZero QOSLevel = 0\n // QOSOne denotes at least once message delivery\n QOSOne QOSLevel = 1\n // QOSTwo denotes exactly once message delivery\n QOSTwo QOSLevel = 2\n)\n")),(0,a.kt)("a",{name:"Resolver"}),"## type [Resolver](https://github.com/gojek/courier-go/blob/main/client_resolver.go#L17-L22)",(0,a.kt)("p",null,"Resolver sends TCPAddress updates on channel returned by UpdateChan","(",")"," channel."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type Resolver interface {\n // UpdateChan returns a channel where TCPAddress updates can be received.\n UpdateChan() <-chan []TCPAddress\n // Done returns a channel which is closed when the Resolver is no longer running.\n Done() <-chan struct{}\n}\n")),(0,a.kt)("a",{name:"Retained"}),"## type [Retained](https://github.com/gojek/courier-go/blob/main/options.go#L26)",(0,a.kt)("p",null,"Retained is an option used with Publisher.Publish call"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type Retained bool\n")),(0,a.kt)("a",{name:"StartOption"}),"## type [StartOption](https://github.com/gojek/courier-go/blob/main/exp_starter.go#L14)",(0,a.kt)("p",null,"StartOption can be used to customise behaviour of ExponentialStartStrategy"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type StartOption func(*startOptions)\n")),(0,a.kt)("a",{name:"WithMaxInterval"}),"### func [WithMaxInterval](https://github.com/gojek/courier-go/blob/main/exp_starter.go#L18)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func WithMaxInterval(interval time.Duration) StartOption\n")),(0,a.kt)("p",null,"WithMaxInterval sets the maximum interval the retry logic will wait before attempting another Client.Start, Default is 30 seconds"),(0,a.kt)("a",{name:"WithOnRetry"}),"### func [WithOnRetry](https://github.com/gojek/courier-go/blob/main/exp_starter.go#L28)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func WithOnRetry(retryFunc func(error)) StartOption\n")),(0,a.kt)("p",null,"WithOnRetry sets the func which is called when there is an error in the previous Client.Start attempt"),(0,a.kt)("a",{name:"Store"}),"## type [Store](https://github.com/gojek/courier-go/blob/main/alias.go#L16)",(0,a.kt)("p",null,"Store is an interface which can be used to provide implementations for message persistence."),(0,a.kt)("p",null,"[","IMPORTANT","]"," When implementing a store with a shared storage ","(","ex: redis",")"," across multiple application instances, it should be ensured that the keys are namespaced for each application instance otherwise there will be collisions. The messages are identified based on message id from the MQTT packets, and they have values in range ","(","0, 2^16",")",", this coincides with max number of in","-","flight messages"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type Store = mqtt.Store\n")),(0,a.kt)("a",{name:"NewMemoryStore"}),"### func [NewMemoryStore](https://github.com/gojek/courier-go/blob/main/alias.go#L21)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func NewMemoryStore() Store\n")),(0,a.kt)("p",null,"NewMemoryStore returns a pointer to a new instance of mqtt.MemoryStore, the instance is not initialized and ready to use until Open","(",")"," has been called on it."),(0,a.kt)("a",{name:"Subscriber"}),"## type [Subscriber](https://github.com/gojek/courier-go/blob/main/subscriber.go#L8-L14)",(0,a.kt)("p",null,"Subscriber defines behaviour of an MQTT subscriber that can create subscriptions."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type Subscriber interface {\n // Subscribe allows to subscribe to messages from an MQTT broker\n Subscribe(ctx context.Context, topic string, callback MessageHandler, opts ...Option) error\n\n // SubscribeMultiple allows to subscribe to messages on multiple topics from an MQTT broker\n SubscribeMultiple(ctx context.Context, topicsWithQos map[string]QOSLevel, callback MessageHandler) error\n}\n")),(0,a.kt)("a",{name:"SubscriberFuncs"}),"## type [SubscriberFuncs](https://github.com/gojek/courier-go/blob/main/subscriber.go#L30-L33)",(0,a.kt)("p",null,"SubscriberFuncs defines signature of a Subscribe function."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type SubscriberFuncs struct {\n // contains filtered or unexported fields\n}\n")),(0,a.kt)("a",{name:"NewSubscriberFuncs"}),"### func [NewSubscriberFuncs](https://github.com/gojek/courier-go/blob/main/subscriber.go#L36-L39)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func NewSubscriberFuncs(subscribeFunc func(context.Context, string, MessageHandler, ...Option) error, subscribeMultipleFunc func(context.Context, map[string]QOSLevel, MessageHandler) error) SubscriberFuncs\n")),(0,a.kt)("p",null,"NewSubscriberFuncs is a helper function to create SubscriberFuncs"),(0,a.kt)("a",{name:"SubscriberFuncs.Subscribe"}),"### func \\(SubscriberFuncs\\) [Subscribe](https://github.com/gojek/courier-go/blob/main/subscriber.go#L44)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func (s SubscriberFuncs) Subscribe(ctx context.Context, topic string, callback MessageHandler, opts ...Option) error\n")),(0,a.kt)("p",null,"Subscribe implements Subscriber interface on SubscriberFuncs."),(0,a.kt)("a",{name:"SubscriberFuncs.SubscribeMultiple"}),"### func \\(SubscriberFuncs\\) [SubscribeMultiple](https://github.com/gojek/courier-go/blob/main/subscriber.go#L49-L53)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func (s SubscriberFuncs) SubscribeMultiple(ctx context.Context, topicsWithQos map[string]QOSLevel, callback MessageHandler) error\n")),(0,a.kt)("p",null,"SubscribeMultiple implements Subscriber interface on SubscriberFuncs."),(0,a.kt)("a",{name:"SubscriberMiddlewareFunc"}),"## type [SubscriberMiddlewareFunc](https://github.com/gojek/courier-go/blob/main/subscriber.go#L22)",(0,a.kt)("p",null,"SubscriberMiddlewareFunc functions are closures that intercept Subscriber.Subscribe calls."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type SubscriberMiddlewareFunc func(Subscriber) Subscriber\n")),(0,a.kt)("a",{name:"SubscriberMiddlewareFunc.Middleware"}),"### func \\(SubscriberMiddlewareFunc\\) [Middleware](https://github.com/gojek/courier-go/blob/main/subscriber.go#L25)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func (smw SubscriberMiddlewareFunc) Middleware(subscriber Subscriber) Subscriber\n")),(0,a.kt)("p",null,"Middleware allows SubscriberMiddlewareFunc to implement the subscribeMiddleware interface."),(0,a.kt)("a",{name:"TCPAddress"}),"## type [TCPAddress](https://github.com/gojek/courier-go/blob/main/client_resolver.go#L11-L14)",(0,a.kt)("p",null,"TCPAddress specifies Host and Port for remote broker"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type TCPAddress struct {\n Host string\n Port uint16\n}\n")),(0,a.kt)("a",{name:"Unsubscriber"}),"## type [Unsubscriber](https://github.com/gojek/courier-go/blob/main/unsubscriber.go#L8-L11)",(0,a.kt)("p",null,"Unsubscriber defines behaviour of an MQTT client that can remove subscriptions."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type Unsubscriber interface {\n // Unsubscribe removes any subscription to messages from an MQTT broker\n Unsubscribe(ctx context.Context, topics ...string) error\n}\n")),(0,a.kt)("a",{name:"UnsubscriberFunc"}),"## type [UnsubscriberFunc](https://github.com/gojek/courier-go/blob/main/unsubscriber.go#L27)",(0,a.kt)("p",null,"UnsubscriberFunc defines signature of a Unsubscribe function."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type UnsubscriberFunc func(context.Context, ...string) error\n")),(0,a.kt)("a",{name:"UnsubscriberFunc.Unsubscribe"}),"### func \\(UnsubscriberFunc\\) [Unsubscribe](https://github.com/gojek/courier-go/blob/main/unsubscriber.go#L30)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func (f UnsubscriberFunc) Unsubscribe(ctx context.Context, topics ...string) error\n")),(0,a.kt)("p",null,"Unsubscribe implements Unsubscriber interface on UnsubscriberFunc."),(0,a.kt)("a",{name:"UnsubscriberMiddlewareFunc"}),"## type [UnsubscriberMiddlewareFunc](https://github.com/gojek/courier-go/blob/main/unsubscriber.go#L19)",(0,a.kt)("p",null,"UnsubscriberMiddlewareFunc functions are closures that intercept Unsubscriber.Unsubscribe calls."),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"type UnsubscriberMiddlewareFunc func(Unsubscriber) Unsubscriber\n")),(0,a.kt)("a",{name:"UnsubscriberMiddlewareFunc.Middleware"}),"### func \\(UnsubscriberMiddlewareFunc\\) [Middleware](https://github.com/gojek/courier-go/blob/main/unsubscriber.go#L22)",(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-go"},"func (usmw UnsubscriberMiddlewareFunc) Middleware(unsubscriber Unsubscriber) Unsubscriber\n")),(0,a.kt)("p",null,"Middleware allows UnsubscriberMiddlewareFunc to implement the unsubscribeMiddleware interface."),(0,a.kt)("p",null,"Generated by ",(0,a.kt)("a",{parentName:"p",href:"https://github.com/princjef/gomarkdoc"},"gomarkdoc")))}b.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/runtime~main.225127f3.js b/assets/js/runtime~main.b3e20785.js similarity index 91% rename from assets/js/runtime~main.225127f3.js rename to assets/js/runtime~main.b3e20785.js index 7421ffb..5d8a62d 100644 --- a/assets/js/runtime~main.225127f3.js +++ b/assets/js/runtime~main.b3e20785.js @@ -1 +1 @@ -(()=>{"use strict";var e,r,t,o,a,f={},n={};function c(e){var r=n[e];if(void 0!==r)return r.exports;var t=n[e]={id:e,loaded:!1,exports:{}};return f[e].call(t.exports,t,t.exports,c),t.loaded=!0,t.exports}c.m=f,c.c=n,e=[],c.O=(r,t,o,a)=>{if(!t){var f=1/0;for(u=0;u=a)&&Object.keys(c.O).every((e=>c.O[e](t[d])))?t.splice(d--,1):(n=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[t,o,a]},c.n=e=>{var r=e&&e.__esModule?()=>e.default:()=>e;return c.d(r,{a:r}),r},t=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,c.t=function(e,o){if(1&o&&(e=this(e)),8&o)return e;if("object"==typeof e&&e){if(4&o&&e.__esModule)return e;if(16&o&&"function"==typeof e.then)return e}var a=Object.create(null);c.r(a);var f={};r=r||[null,t({}),t([]),t(t)];for(var n=2&o&&e;"object"==typeof n&&!~r.indexOf(n);n=t(n))Object.getOwnPropertyNames(n).forEach((r=>f[r]=()=>e[r]));return f.default=()=>e,c.d(a,f),a},c.d=(e,r)=>{for(var t in r)c.o(r,t)&&!c.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},c.f={},c.e=e=>Promise.all(Object.keys(c.f).reduce(((r,t)=>(c.f[t](e,r),r)),[])),c.u=e=>"assets/js/"+({26:"1da63148",53:"935f2afb",62:"2c5f8529",139:"df26bbec",162:"d589d3a7",167:"4439e52c",192:"d91b1605",195:"c4f5d8e4",235:"918f3a65",242:"4b0f5cdf",259:"cf79d31c",404:"9efdda36",425:"d2e312ec",514:"1be78505",582:"e0fb8c24",688:"ee8065c9",713:"eae8b411",777:"769886d0",809:"67c3e4ff",918:"17896441",990:"0a887687"}[e]||e)+"."+{26:"7a3a4350",53:"4856b569",62:"a6b24f9e",139:"511e9003",162:"30f90784",167:"2f707d09",192:"f65a7a39",195:"e4f3f11b",235:"b774dc3d",242:"8b56bb1b",259:"7d07ae74",404:"cf75e5e1",425:"54ef22b8",514:"b07503e1",582:"1622f312",688:"fd833a71",713:"d82b4efe",777:"11feffe9",809:"6d8ac053",918:"2061b3fa",972:"eaf28fba",990:"a6a0d0f0"}[e]+".js",c.miniCssF=e=>{},c.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),c.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),o={},a="courier:",c.l=(e,r,t,f)=>{if(o[e])o[e].push(r);else{var n,d;if(void 0!==t)for(var i=document.getElementsByTagName("script"),u=0;u{n.onerror=n.onload=null,clearTimeout(s);var a=o[e];if(delete o[e],n.parentNode&&n.parentNode.removeChild(n),a&&a.forEach((e=>e(t))),r)return r(t)},s=setTimeout(b.bind(null,void 0,{type:"timeout",target:n}),12e4);n.onerror=b.bind(null,n.onerror),n.onload=b.bind(null,n.onload),d&&document.head.appendChild(n)}},c.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},c.p="/courier-go/",c.gca=function(e){return e={17896441:"918","1da63148":"26","935f2afb":"53","2c5f8529":"62",df26bbec:"139",d589d3a7:"162","4439e52c":"167",d91b1605:"192",c4f5d8e4:"195","918f3a65":"235","4b0f5cdf":"242",cf79d31c:"259","9efdda36":"404",d2e312ec:"425","1be78505":"514",e0fb8c24:"582",ee8065c9:"688",eae8b411:"713","769886d0":"777","67c3e4ff":"809","0a887687":"990"}[e]||e,c.p+c.u(e)},(()=>{var e={303:0,532:0};c.f.j=(r,t)=>{var o=c.o(e,r)?e[r]:void 0;if(0!==o)if(o)t.push(o[2]);else if(/^(303|532)$/.test(r))e[r]=0;else{var a=new Promise(((t,a)=>o=e[r]=[t,a]));t.push(o[2]=a);var f=c.p+c.u(r),n=new Error;c.l(f,(t=>{if(c.o(e,r)&&(0!==(o=e[r])&&(e[r]=void 0),o)){var a=t&&("load"===t.type?"missing":t.type),f=t&&t.target&&t.target.src;n.message="Loading chunk "+r+" failed.\n("+a+": "+f+")",n.name="ChunkLoadError",n.type=a,n.request=f,o[1](n)}}),"chunk-"+r,r)}},c.O.j=r=>0===e[r];var r=(r,t)=>{var o,a,f=t[0],n=t[1],d=t[2],i=0;if(f.some((r=>0!==e[r]))){for(o in n)c.o(n,o)&&(c.m[o]=n[o]);if(d)var u=d(c)}for(r&&r(t);i{"use strict";var e,r,t,o,a,f={},n={};function c(e){var r=n[e];if(void 0!==r)return r.exports;var t=n[e]={id:e,loaded:!1,exports:{}};return f[e].call(t.exports,t,t.exports,c),t.loaded=!0,t.exports}c.m=f,c.c=n,e=[],c.O=(r,t,o,a)=>{if(!t){var f=1/0;for(u=0;u=a)&&Object.keys(c.O).every((e=>c.O[e](t[d])))?t.splice(d--,1):(n=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[t,o,a]},c.n=e=>{var r=e&&e.__esModule?()=>e.default:()=>e;return c.d(r,{a:r}),r},t=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,c.t=function(e,o){if(1&o&&(e=this(e)),8&o)return e;if("object"==typeof e&&e){if(4&o&&e.__esModule)return e;if(16&o&&"function"==typeof e.then)return e}var a=Object.create(null);c.r(a);var f={};r=r||[null,t({}),t([]),t(t)];for(var n=2&o&&e;"object"==typeof n&&!~r.indexOf(n);n=t(n))Object.getOwnPropertyNames(n).forEach((r=>f[r]=()=>e[r]));return f.default=()=>e,c.d(a,f),a},c.d=(e,r)=>{for(var t in r)c.o(r,t)&&!c.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},c.f={},c.e=e=>Promise.all(Object.keys(c.f).reduce(((r,t)=>(c.f[t](e,r),r)),[])),c.u=e=>"assets/js/"+({26:"1da63148",53:"935f2afb",62:"2c5f8529",139:"df26bbec",162:"d589d3a7",167:"4439e52c",192:"d91b1605",195:"c4f5d8e4",235:"918f3a65",242:"4b0f5cdf",259:"cf79d31c",404:"9efdda36",425:"d2e312ec",514:"1be78505",582:"e0fb8c24",688:"ee8065c9",713:"eae8b411",777:"769886d0",809:"67c3e4ff",918:"17896441",990:"0a887687"}[e]||e)+"."+{26:"7a3a4350",53:"4856b569",62:"a6b24f9e",139:"511e9003",162:"30f90784",167:"2f707d09",192:"f65a7a39",195:"e4f3f11b",235:"b774dc3d",242:"8b56bb1b",259:"7d07ae74",404:"cf75e5e1",425:"54ef22b8",514:"b07503e1",582:"1622f312",688:"fd833a71",713:"d82b4efe",777:"11feffe9",809:"6d8ac053",918:"2061b3fa",972:"eaf28fba",990:"0cb8b9f7"}[e]+".js",c.miniCssF=e=>{},c.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),c.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),o={},a="courier:",c.l=(e,r,t,f)=>{if(o[e])o[e].push(r);else{var n,d;if(void 0!==t)for(var i=document.getElementsByTagName("script"),u=0;u{n.onerror=n.onload=null,clearTimeout(s);var a=o[e];if(delete o[e],n.parentNode&&n.parentNode.removeChild(n),a&&a.forEach((e=>e(t))),r)return r(t)},s=setTimeout(l.bind(null,void 0,{type:"timeout",target:n}),12e4);n.onerror=l.bind(null,n.onerror),n.onload=l.bind(null,n.onload),d&&document.head.appendChild(n)}},c.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},c.p="/courier-go/",c.gca=function(e){return e={17896441:"918","1da63148":"26","935f2afb":"53","2c5f8529":"62",df26bbec:"139",d589d3a7:"162","4439e52c":"167",d91b1605:"192",c4f5d8e4:"195","918f3a65":"235","4b0f5cdf":"242",cf79d31c:"259","9efdda36":"404",d2e312ec:"425","1be78505":"514",e0fb8c24:"582",ee8065c9:"688",eae8b411:"713","769886d0":"777","67c3e4ff":"809","0a887687":"990"}[e]||e,c.p+c.u(e)},(()=>{var e={303:0,532:0};c.f.j=(r,t)=>{var o=c.o(e,r)?e[r]:void 0;if(0!==o)if(o)t.push(o[2]);else if(/^(303|532)$/.test(r))e[r]=0;else{var a=new Promise(((t,a)=>o=e[r]=[t,a]));t.push(o[2]=a);var f=c.p+c.u(r),n=new Error;c.l(f,(t=>{if(c.o(e,r)&&(0!==(o=e[r])&&(e[r]=void 0),o)){var a=t&&("load"===t.type?"missing":t.type),f=t&&t.target&&t.target.src;n.message="Loading chunk "+r+" failed.\n("+a+": "+f+")",n.name="ChunkLoadError",n.type=a,n.request=f,o[1](n)}}),"chunk-"+r,r)}},c.O.j=r=>0===e[r];var r=(r,t)=>{var o,a,f=t[0],n=t[1],d=t[2],i=0;if(f.some((r=>0!==e[r]))){for(o in n)c.o(n,o)&&(c.m[o]=n[o]);if(d)var u=d(c)}for(r&&r(t);i Middlewares | Courier Go - + - + \ No newline at end of file diff --git a/docs/Tutorials/Middlewares/logging/index.html b/docs/Tutorials/Middlewares/logging/index.html index e1ecc7b..726beb3 100644 --- a/docs/Tutorials/Middlewares/logging/index.html +++ b/docs/Tutorials/Middlewares/logging/index.html @@ -4,13 +4,13 @@ Logging | Courier Go - +

Logging

A logging middleware is helpful to give information whenever you invoke client.Publish(), the call is first passed through the chain of middlewares and then published to broker.

publish_logger.go
type chatMessage struct {
From string `json:"from"`
To string `json:"to"`
Data interface{} `json:"data"`
}

var client *courier.Client

client.UsePublisherMiddleware(func(next courier.Publisher) courier.Publisher {
return courier.PublisherFunc(func(ctx context.Context, topic string, data interface{}, opts ...courier.Option) error {
if msg, ok := data.(*chatMessage); ok {
log.Printf("Sending message from %s to %s", msg.From, msg.To)
}

if err := next.Publish(ctx, topic, data, opts...); err != nil {
log.Printf("err sending message: %s", err)

return err
}

return nil
})
})
- + \ No newline at end of file diff --git a/docs/Tutorials/Middlewares/metrics/index.html b/docs/Tutorials/Middlewares/metrics/index.html index 25671e7..15ceca8 100644 --- a/docs/Tutorials/Middlewares/metrics/index.html +++ b/docs/Tutorials/Middlewares/metrics/index.html @@ -4,13 +4,13 @@ Metrics | Courier Go - +

Metrics

A metric middleware is helpful to track and aggregate metrics whenever you invoke client.Publish(), the call is first passed through the chain of middlewares and then published to broker.

publish_metrics.go
func main() {
var client *courier.Client

pm := &promCollector{}

client.UsePublisherMiddleware(pm.publisherMiddleware)
}

type promCollector struct {
attemps *prometheus.CounterVec
errors *prometheus.CounterVec
success *prometheus.CounterVec
}

func (p *promCollector) publisherMiddleware(next courier.Publisher) courier.Publisher {
return courier.PublisherFunc(func(ctx context.Context, topic string, data interface{}, opts ...courier.Option) error {
p.attemps.With(prometheus.Labels{}).Inc()

if err := next.Publish(ctx, topic, data, opts...); err != nil {
p.errors.With(prometheus.Labels{}).Inc()

return err
}

p.success.With(prometheus.Labels{}).Inc()

return nil
})
}

- + \ No newline at end of file diff --git a/docs/Tutorials/connect/index.html b/docs/Tutorials/connect/index.html index 064e50f..5e8e244 100644 --- a/docs/Tutorials/connect/index.html +++ b/docs/Tutorials/connect/index.html @@ -4,13 +4,13 @@ Connect to Broker | Courier Go - +

Connect to Broker

Create a new courier client and provide broker address to it. Upon calling .Start() the client will attempt to connect to the broker.

You can verify the connection by calling .IsConnected() and it should return true.

connect.go
c, err := courier.NewClient(
courier.WithAddress("broker.emqx.io", 1883),
// courier.WithUsername("username"),
// courier.WithPassword("password"),
)

if err != nil {
panic(err)
}

if err := c.Start(); err != nil {
panic(err)
}

fmt.Println(c.IsConnected())
- + \ No newline at end of file diff --git a/docs/Tutorials/connect_background/index.html b/docs/Tutorials/connect_background/index.html index 80bb898..229e663 100644 --- a/docs/Tutorials/connect_background/index.html +++ b/docs/Tutorials/connect_background/index.html @@ -4,13 +4,13 @@ Background Broker Connect | Courier Go - +

Background Broker Connect

Create a new courier client and provide broker address to it.

You can start the client in background with courier.ExponentialStartStrategy which will keep trying to connect to the broker until the context is cancelled.

You can wait for the connection with courier.WaitForConnection and verify the connection by calling .IsConnected() and it should return true.

background_connect.go
c, err := courier.NewClient(
courier.WithAddress("broker.emqx.io", 1883),
// courier.WithUsername("username"),
// courier.WithPassword("password"),
)

if err != nil {
panic(err)
}

ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill)

courier.ExponentialStartStrategy(ctx, c)

courier.WaitForConnection(c, 5*time.Second, 100*time.Millisecond)

fmt.Println(c.IsConnected())
- + \ No newline at end of file diff --git a/docs/Tutorials/custom_codec/index.html b/docs/Tutorials/custom_codec/index.html index e07f3d0..8e453e8 100644 --- a/docs/Tutorials/custom_codec/index.html +++ b/docs/Tutorials/custom_codec/index.html @@ -4,13 +4,13 @@ Custom Message Codec | Courier Go - +

Custom Message Codec

Writing Custom Encoder Decoder

First write a custom encoder and decoder to work with the data types your project uses.

One common codec is protobuf.

decoder.go
var bufPool = &sync.Pool{
New: func() interface{} {
return new(bytes.Buffer)
},
}

// NewDecoder returns a new decoder that reads from r.
//
// The decoder introduces its own buffering.
func NewDecoder(r io.Reader) *Decoder {
return &Decoder{r: r}
}

// A Decoder reads and decodes proto values from an input stream.
type Decoder struct {
r io.Reader
}

// Decode reads the proto-encoded value from its
// input and stores it in the value pointed to by v.
func (d *Decoder) Decode(v interface{}) error {
m, ok := v.(proto.Message)
if !ok {
return errors.New("value should be a proto.Message")
}

buf := bufPool.Get().(*bytes.Buffer)
defer bufPool.Put(buf)

buf.Reset()

if _, err := buf.ReadFrom(d.r); err != nil {
return err
}

if err := proto.Unmarshal(buf.Bytes(), m); err != nil {
return err
}

return nil
}
encoder.go
// NewEncoder returns a new encoder that writes to w.
func NewEncoder(w io.Writer) *Encoder {
return &Encoder{w: w}
}

// An Encoder writes proto values to an output stream.
type Encoder struct {
w io.Writer
}

// Encode writes the proto encoding of v to the stream.
func (e *Encoder) Encode(v interface{}) error {
m, ok := v.(proto.Message)
if !ok {
return errors.New("value should be a proto.Message")
}

b, err := proto.Marshal(m)
if err != nil {
return err
}

if _, err := e.w.Write(b); err != nil {
return err
}

return nil
}

Registering Encoder Decoder

You can then use this codec to encode/decode protobuf messages with courier client.

client.go
client, _ := courier.NewClient(
courier.WithCustomEncoder(func(w io.Writer) courier.Encoder { return NewEncoder(w) }),
courier.WithCustomDecoder(func(r io.Reader) courier.Decoder { return NewDecoder(r) }),
)
- + \ No newline at end of file diff --git a/docs/Tutorials/publish/index.html b/docs/Tutorials/publish/index.html index f2eee55..d59fa6f 100644 --- a/docs/Tutorials/publish/index.html +++ b/docs/Tutorials/publish/index.html @@ -4,13 +4,13 @@ Publish Message | Courier Go - +

Publish Message

Once you have initialised the courier client and established a connection with the broker, you can publish message in the following way.

publisher.go
type chatMessage struct {
From string `json:"from"`
To string `json:"to"`
Data interface{} `json:"data"`
}

msg := &chatMessage{
From: "test-username-1",
To: "test-username-2",
Data: map[string]string{
"message": "Hi, User 2!",
},
}

var client courier.Publisher

_ = client.Publish(context.Background(), "chat/test-username-2/send", msg)
- + \ No newline at end of file diff --git a/docs/Tutorials/subscribe/index.html b/docs/Tutorials/subscribe/index.html index 9536b72..058bb9f 100644 --- a/docs/Tutorials/subscribe/index.html +++ b/docs/Tutorials/subscribe/index.html @@ -4,13 +4,13 @@ Subscribe Messages | Courier Go - +

Subscribe Messages

You can add a subscription to a topic and respond to message as well when you receive a message.

For example, you can relay the received_at time back to the sender by publishing a message.

subscriber.go
type chatMessage struct {
From string `json:"from"`
To string `json:"to"`
Data interface{} `json:"data"`
}

type status struct {
ReceivedAt time.Time `json:"received_at"`
}

cb := func(ctx context.Context, ps courier.PubSub, m *courier.Message) {
msg := new(chatMessage)
if err := m.DecodePayload(msg); err != nil {
// Log Error or Panic
}

_ = ps.Publish(ctx, fmt.Sprintf("chat/%s/send", msg.From), &status{ReceivedAt: time.Now()})
}

var client courier.Subscriber

_ = client.Subscribe(context.Background(), "chat/test-username-2/send", cb)
- + \ No newline at end of file diff --git a/docs/getting-started/index.html b/docs/getting-started/index.html index 8289537..f9eac66 100644 --- a/docs/getting-started/index.html +++ b/docs/getting-started/index.html @@ -4,13 +4,13 @@ Getting Started | Courier Go - +

Getting Started

Introduction

Courier Golang client library provides an opinionated wrapper over paho MQTT library to add features on top of it.

Long running connection is a persistent connection established between client & server for instant bi-directional communication. A long running connection is maintained for maximum possible duration with the help of keep alive packets. This helps in saving battery and data on mobile devices.

MQTT is an extremely lightweight protocol which works on publish/subscribe messaging model. It is designed for connections with remote locations where a "small code footprint" is required or the network bandwidth is limited.

The protocol usually runs over TCP/IP; however, any network protocol that provides ordered, lossless, bi-directional connections can support MQTT.

MQTT has 3 built-in QoS levels for Reliable Message Delivery:

  • QoS 0(At most once) - the message is sent only once and the client and broker take no additional steps to acknowledge delivery (fire and forget).
  • QoS 1(At least once) - the message is re-tried by the sender multiple times until acknowledgement is received (acknowledged delivery).
  • QoS 2(Exactly once) - the sender and receiver engage in a two-level handshake to ensure only one copy of the message is received (assured delivery).

Usage

go get -u github.com/gojek/courier-go

Create a main.go file and add the following code to it.

package main

import (
"context"
"fmt"
"os"
"os/signal"
"time"

"github.com/gojek/courier-go"
)

func main() {
c, err := courier.NewClient(
courier.WithUsername("username"),
courier.WithPassword("password"),
courier.WithAddress("localhost", 1883),
)

if err != nil {
panic(err)
}

if err := c.Start(); err != nil {
panic(err)
}

ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill)

tick := time.NewTicker(time.Second)
for {
select {
case t := <-tick.C:
msg := map[string]interface{}{
"time": t.UnixNano(),
}
if err := c.Publish(context.Background(), "topic", msg, courier.QOSOne); err != nil {
fmt.Printf("Publish() error = %s\n", err)
} else {
fmt.Println("Publish() success")
}
case <-ctx.Done():
tick.Stop()
c.Stop()
}
}
}
- + \ No newline at end of file diff --git a/docs/sdk/index.html b/docs/sdk/index.html index a7e071a..39a758a 100644 --- a/docs/sdk/index.html +++ b/docs/sdk/index.html @@ -4,13 +4,13 @@ SDK | Courier Go - +
-

SDK

courier

import "github.com/gojek/courier-go"

Package courier contains the client that can be used to interact with the courier infrastructure to publish/subscribe to messages from other clients

Index

Variables

var (
// ErrConnectTimeout indicates connection timeout while connecting to broker.
ErrConnectTimeout = errors.New("client timed out while trying to connect to the broker")
// ErrPublishTimeout indicates publish timeout.
ErrPublishTimeout = errors.New("publish timeout")
// ErrSubscribeTimeout indicates subscribe timeout.
ErrSubscribeTimeout = errors.New("subscribe timeout")
// ErrUnsubscribeTimeout indicates unsubscribe timeout.
ErrUnsubscribeTimeout = errors.New("unsubscribe timeout")
// ErrSubscribeMultipleTimeout indicates multiple subscribe timeout.
ErrSubscribeMultipleTimeout = errors.New("subscribe multiple timeout")
)
## func [ExponentialStartStrategy](https://github.com/gojek/courier-go/blob/main/exp_starter.go#L37)
func ExponentialStartStrategy(ctx context.Context, c interface{ Start() error }, opts ...StartOption)

ExponentialStartStrategy will keep attempting to call Client.Start in the background and retry on error, it will never exit unless the context used to invoke is cancelled. This will NOT stop the client, that is the responsibility of caller.

## func [Version](https://github.com/gojek/courier-go/blob/main/version.go#L4)
func Version() string

Version can be used to get the current courier library version

## func [WaitForConnection](https://github.com/gojek/courier-go/blob/main/utils.go#L10)
func WaitForConnection(c ConnectionInformer, waitFor time.Duration, tick time.Duration) bool

WaitForConnection checks if the Client is connected, it calls ConnectionInformer.IsConnected after every tick and waitFor is the maximum duration it can block. Returns true only when ConnectionInformer.IsConnected returns true

## type [Client](https://github.com/gojek/courier-go/blob/main/client.go#L17-L29)

Client allows to communicate with an MQTT broker

type Client struct {
// contains filtered or unexported fields
}
### func [NewClient](https://github.com/gojek/courier-go/blob/main/client.go#L34)
func NewClient(opts ...ClientOption) (*Client, error)

NewClient creates the Client struct with the clientOptions provided, it can return error when prometheus.DefaultRegisterer has already been used to register the collected metrics

Example

c, err := courier.NewClient(
courier.WithUsername("username"),
courier.WithPassword("password"),
courier.WithAddress("localhost", 1883),
)

if err != nil {
panic(err)
}

if err := c.Start(); err != nil {
panic(err)
}

stopCh := make(chan os.Signal, 1)
signal.Notify(stopCh, []os.Signal{os.Interrupt, syscall.SIGTERM}...)

go func() {
tick := time.NewTicker(time.Second)
for {
select {
case t := <-tick.C:
msg := map[string]interface{}{
"time": t.UnixNano(),
}
if err := c.Publish(context.Background(), "topic", msg, courier.QOSOne); err != nil {
fmt.Printf("Publish() error = %s\n", err)
} else {
fmt.Println("Publish() success")
}
case <-stopCh:
tick.Stop()
return
}
}
}()

<-stopCh
c.Stop()

### func \(\*Client\) [IsConnected](https://github.com/gojek/courier-go/blob/main/client.go#L59)
func (c *Client) IsConnected() (online bool)

IsConnected checks whether the client is connected to the broker

### func \(\*Client\) [Publish](https://github.com/gojek/courier-go/blob/main/client_publish.go#L11)
func (c *Client) Publish(ctx context.Context, topic string, message interface{}, opts ...Option) error

Publish allows to publish messages to an MQTT broker

### func \(\*Client\) [Run](https://github.com/gojek/courier-go/blob/main/client.go#L110)
func (c *Client) Run(ctx context.Context) error

Run will start running the Client. This makes Client compatible with github.com/gojekfarm/xrun package. https://pkg.go.dev/github.com/gojekfarm/xrun

### func \(\*Client\) [Start](https://github.com/gojek/courier-go/blob/main/client.go#L68)
func (c *Client) Start() (err error)

Start will attempt to connect to the broker.

### func \(\*Client\) [Stop](https://github.com/gojek/courier-go/blob/main/client.go#L102)
func (c *Client) Stop()

Stop will disconnect from the broker and finish up any pending work on internal communication workers. This can only block until the period configured with the ClientOption WithGracefulShutdownPeriod.

### func \(\*Client\) [Subscribe](https://github.com/gojek/courier-go/blob/main/client_subscribe.go#L11)
func (c *Client) Subscribe(ctx context.Context, topic string, callback MessageHandler, opts ...Option) error

Subscribe allows to subscribe to messages from an MQTT broker

### func \(\*Client\) [SubscribeMultiple](https://github.com/gojek/courier-go/blob/main/client_subscribe.go#L16-L20)
func (c *Client) SubscribeMultiple(ctx context.Context, topicsWithQos map[string]QOSLevel, callback MessageHandler) error

SubscribeMultiple allows to subscribe to messages on multiple topics from an MQTT broker

### func \(\*Client\) [Unsubscribe](https://github.com/gojek/courier-go/blob/main/client_unsubscribe.go#L10)
func (c *Client) Unsubscribe(ctx context.Context, topics ...string) error

Unsubscribe removes any subscription to messages from an MQTT broker

### func \(\*Client\) [UsePublisherMiddleware](https://github.com/gojek/courier-go/blob/main/client_publish.go#L18)
func (c *Client) UsePublisherMiddleware(mwf ...PublisherMiddlewareFunc)

UsePublisherMiddleware appends a PublisherMiddlewareFunc to the chain. Middleware can be used to intercept or otherwise modify, process or skip messages. They are executed in the order that they are applied to the Client.

### func \(\*Client\) [UseSubscriberMiddleware](https://github.com/gojek/courier-go/blob/main/client_subscribe.go#L27)
func (c *Client) UseSubscriberMiddleware(mwf ...SubscriberMiddlewareFunc)

UseSubscriberMiddleware appends a SubscriberMiddlewareFunc to the chain. Middleware can be used to intercept or otherwise modify, process or skip subscriptions. They are executed in the order that they are applied to the Client.

### func \(\*Client\) [UseUnsubscriberMiddleware](https://github.com/gojek/courier-go/blob/main/client_unsubscribe.go#L17)
func (c *Client) UseUnsubscriberMiddleware(mwf ...UnsubscriberMiddlewareFunc)

UseUnsubscriberMiddleware appends a UnsubscriberMiddlewareFunc to the chain. Middleware can be used to intercept or otherwise modify, process or skip subscriptions. They are executed in the order that they are applied to the Client.

## type [ClientOption](https://github.com/gojek/courier-go/blob/main/client_options.go#L12)

ClientOption allows to configure the behaviour of a Client.

type ClientOption interface {
// contains filtered or unexported methods
}
### func [WithAddress](https://github.com/gojek/courier-go/blob/main/client_options.go#L115)
func WithAddress(host string, port uint16) ClientOption

WithAddress sets the broker address to be used. To establish a TLS connection, use WithTLS Option along with this. Default values for hostname is "127.0.0.1" and for port is 1883.

### func [WithAutoReconnect](https://github.com/gojek/courier-go/blob/main/client_options.go#L45)
func WithAutoReconnect(autoReconnect bool) ClientOption

WithAutoReconnect sets whether the automatic reconnection logic should be used when the connection is lost, even if disabled the WithOnConnectionLost is still called.

### func [WithCleanSession](https://github.com/gojek/courier-go/blob/main/client_options.go#L57)
func WithCleanSession(cleanSession bool) ClientOption

WithCleanSession will set the "clean session" flag in the connect message when this client connects to an MQTT broker. By setting this flag, you are indicating that no messages saved by the broker for this client should be delivered. Any messages that were going to be sent by this client before disconnecting but didn't, will not be sent upon connecting to the broker.

### func [WithClientID](https://github.com/gojek/courier-go/blob/main/client_options.go#L16)
func WithClientID(clientID string) ClientOption

WithClientID sets the clientID to be used while connecting to an MQTT broker. According to the MQTT v3.1 specification, a client id must be no longer than 23 characters.

### func [WithConnectTimeout](https://github.com/gojek/courier-go/blob/main/client_options.go#L134)
func WithConnectTimeout(duration time.Duration) ClientOption

WithConnectTimeout limits how long the client will wait when trying to open a connection to an MQTT server before timing out. A duration of 0 never times out. Default 15 seconds.

### func [WithCustomDecoder](https://github.com/gojek/courier-go/blob/main/client_options.go#L176)
func WithCustomDecoder(decoderFunc DecoderFunc) ClientOption

WithCustomDecoder allows to decode message bytes into the desired object.

### func [WithCustomEncoder](https://github.com/gojek/courier-go/blob/main/client_options.go#L173)
func WithCustomEncoder(encoderFunc EncoderFunc) ClientOption

WithCustomEncoder allows to transform objects into the desired message bytes.

### func [WithGracefulShutdownPeriod](https://github.com/gojek/courier-go/blob/main/client_options.go#L158)
func WithGracefulShutdownPeriod(duration time.Duration) ClientOption

WithGracefulShutdownPeriod sets the limit that is allowed for existing work to be completed.

### func [WithKeepAlive](https://github.com/gojek/courier-go/blob/main/client_options.go#L125)
func WithKeepAlive(duration time.Duration) ClientOption

WithKeepAlive will set the amount of time (in seconds) that the client should wait before sending a PING request to the broker. This will allow the client to know that a connection has not been lost with the server.

### func [WithMaintainOrder](https://github.com/gojek/courier-go/blob/main/client_options.go#L71)
func WithMaintainOrder(maintainOrder bool) ClientOption

WithMaintainOrder will set the message routing to guarantee order within each QoS level. By default, this value is true. If set to false (recommended), this flag indicates that messages can be delivered asynchronously from the client to the application and possibly arrive out of order. Specifically, the message handler is called in its own go routine. Note that setting this to true does not guarantee in-order delivery (this is subject to broker settings like "max_inflight_messages=1") and if true then MessageHandler callback must not block.

### func [WithMaxReconnectInterval](https://github.com/gojek/courier-go/blob/main/client_options.go#L151)
func WithMaxReconnectInterval(duration time.Duration) ClientOption

WithMaxReconnectInterval sets the maximum time that will be waited between reconnection attempts. when connection is lost

### func [WithOnConnect](https://github.com/gojek/courier-go/blob/main/client_options.go#L79)
func WithOnConnect(handler OnConnectHandler) ClientOption

WithOnConnect will set the OnConnectHandler callback to be called when the client is connected. Both at initial connection time and upon automatic reconnect.

### func [WithOnConnectionLost](https://github.com/gojek/courier-go/blob/main/client_options.go#L87)
func WithOnConnectionLost(handler OnConnectionLostHandler) ClientOption

WithOnConnectionLost will set the OnConnectionLostHandler callback to be executed in the case where the client unexpectedly loses connection with the MQTT broker.

### func [WithOnReconnect](https://github.com/gojek/courier-go/blob/main/client_options.go#L95)
func WithOnReconnect(handler OnReconnectHandler) ClientOption

WithOnReconnect sets the OnReconnectHandler callback to be executed prior to the client attempting a reconnect to the MQTT broker.

### func [WithPassword](https://github.com/gojek/courier-go/blob/main/client_options.go#L30)
func WithPassword(password string) ClientOption

WithPassword sets the password to be used while connecting to an MQTT broker.

### func [WithPersistence](https://github.com/gojek/courier-go/blob/main/client_options.go#L166)
func WithPersistence(store Store) ClientOption

WithPersistence allows to configure the store to be used by broker Default persistence is in-memory persistence with mqtt.MemoryStore

### func [WithResolver](https://github.com/gojek/courier-go/blob/main/client_resolver.go#L25)
func WithResolver(resolver Resolver) ClientOption

WithResolver sets the specified Resolver.

### func [WithTCPAddress](https://github.com/gojek/courier-go/blob/main/client_options.go#L106)
func WithTCPAddress(host string, port uint16) ClientOption

WithTCPAddress sets the broker address to be used. Default values for hostname is "127.0.0.1" and for port is 1883.

Deprecated: This Option used to work with plain TCP connections, it's now possible to use TLS with WithAddress and WithTLS combination.

### func [WithTLS](https://github.com/gojek/courier-go/blob/main/client_options.go#L37)
func WithTLS(tlsConfig *tls.Config) ClientOption

WithTLS sets the TLs configuration to be used while connecting to an MQTT broker.

### func [WithUseBase64Decoder](https://github.com/gojek/courier-go/blob/main/client_options.go#L180)
func WithUseBase64Decoder() ClientOption

WithUseBase64Decoder configures a json decoder with a base64.StdEncoding wrapped decoder which decodes base64 encoded message bytes into the passed object.

### func [WithUsername](https://github.com/gojek/courier-go/blob/main/client_options.go#L23)
func WithUsername(username string) ClientOption

WithUsername sets the username to be used while connecting to an MQTT broker.

### func [WithWriteTimeout](https://github.com/gojek/courier-go/blob/main/client_options.go#L143)
func WithWriteTimeout(duration time.Duration) ClientOption

WithWriteTimeout limits how long the client will wait when trying to publish, subscribe or unsubscribe on topic when a context deadline is not set while calling Publisher.Publish, Subscriber.Subscribe, Subscriber.SubscribeMultiple or Unsubscriber.Unsubscribe.

## type [ConnectionInformer](https://github.com/gojek/courier-go/blob/main/interface.go#L13-L16)

ConnectionInformer can be used to get information about the connection

type ConnectionInformer interface {
// IsConnected checks whether the client is connected to the broker
IsConnected() bool
}
## type [Decoder](https://github.com/gojek/courier-go/blob/main/decoder.go#L16-L19)

Decoder helps to decode message bytes into the desired object

type Decoder interface {
// Decode decodes message bytes into the passed object
Decode(v interface{}) error
}
### func [DefaultDecoderFunc](https://github.com/gojek/courier-go/blob/main/decoder.go#L22)
func DefaultDecoderFunc(_ context.Context, r io.Reader) Decoder

DefaultDecoderFunc is a DecoderFunc that uses a json.Decoder as the Decoder.

## type [DecoderFunc](https://github.com/gojek/courier-go/blob/main/decoder.go#L13)

DecoderFunc is used to create a Decoder from io.Reader stream of message bytes before calling MessageHandler; the context.Context value may be used to select appropriate Decoder.

type DecoderFunc func(context.Context, io.Reader) Decoder
## type [Encoder](https://github.com/gojek/courier-go/blob/main/encoder.go#L14-L17)

Encoder helps in transforming objects to message bytes

type Encoder interface {
// Encode takes any object and encodes it into bytes
Encode(v interface{}) error
}
### func [DefaultEncoderFunc](https://github.com/gojek/courier-go/blob/main/encoder.go#L20)
func DefaultEncoderFunc(_ context.Context, w io.Writer) Encoder

DefaultEncoderFunc is a EncoderFunc that uses a json.Encoder as the Encoder.

## type [EncoderFunc](https://github.com/gojek/courier-go/blob/main/encoder.go#L11)

EncoderFunc is used to create an Encoder from io.Writer; the context.Context value may be used to select appropriate Encoder.

type EncoderFunc func(context.Context, io.Writer) Encoder
## type [Message](https://github.com/gojek/courier-go/blob/main/message.go#L4-L12)

Message represents the entity that is being relayed via the courier MQTT brokers from Publisher(s) to Subscriber(s).

type Message struct {
ID int
Topic string
Duplicate bool
Retained bool
QoS QOSLevel
// contains filtered or unexported fields
}
### func [NewMessageWithDecoder](https://github.com/gojek/courier-go/blob/main/message.go#L15-L17)
func NewMessageWithDecoder(payloadDecoder Decoder) *Message

NewMessageWithDecoder is a helper to create Message, ideally payloadDecoder should not be mutated once created.

### func \(\*Message\) [DecodePayload](https://github.com/gojek/courier-go/blob/main/message.go#L24)
func (m *Message) DecodePayload(v interface{}) error

DecodePayload can decode the message payload bytes into the desired object.

## type [MessageHandler](https://github.com/gojek/courier-go/blob/main/types.go#L24)

MessageHandler is the type that all callbacks being passed to Subscriber must satisfy.

type MessageHandler func(context.Context, PubSub, *Message)
## type [OnConnectHandler](https://github.com/gojek/courier-go/blob/main/types.go#L10)

OnConnectHandler is a callback that is called when the client state changes from disconnected to connected. Both at initial connection and on reconnection

type OnConnectHandler func(PubSub)
## type [OnConnectionLostHandler](https://github.com/gojek/courier-go/blob/main/types.go#L16)

OnConnectionLostHandler is a callback type which can be set to be executed upon an unintended disconnection from the MQTT broker. Disconnects caused by calling Disconnect or ForceDisconnect will not cause an WithOnConnectionLost callback to execute.

type OnConnectionLostHandler func(error)
## type [OnReconnectHandler](https://github.com/gojek/courier-go/blob/main/types.go#L20)

OnReconnectHandler is invoked prior to reconnecting after the initial connection is lost

type OnReconnectHandler func(PubSub)
## type [Option](https://github.com/gojek/courier-go/blob/main/options.go#L4-L6)

Option changes behaviour of Publisher.Publish, Subscriber.Subscribe calls.

type Option interface {
// contains filtered or unexported methods
}
## type [PubSub](https://github.com/gojek/courier-go/blob/main/interface.go#L5-L10)

PubSub exposes all the operational functionalities of Client with Publisher, Subscriber, Unsubscriber and ConnectionInformer

type PubSub interface {
Publisher
Subscriber
Unsubscriber
ConnectionInformer
}
## type [Publisher](https://github.com/gojek/courier-go/blob/main/publisher.go#L8-L11)

Publisher defines behaviour of an MQTT publisher that can send messages.

type Publisher interface {
// Publish allows to publish messages to an MQTT broker
Publish(ctx context.Context, topic string, message interface{}, options ...Option) error
}
## type [PublisherFunc](https://github.com/gojek/courier-go/blob/main/publisher.go#L14)

PublisherFunc defines signature of a Publish function.

type PublisherFunc func(context.Context, string, interface{}, ...Option) error
### func \(PublisherFunc\) [Publish](https://github.com/gojek/courier-go/blob/main/publisher.go#L17-L22)
func (f PublisherFunc) Publish(ctx context.Context, topic string, message interface{}, opts ...Option) error

Publish implements Publisher interface on PublisherFunc.

## type [PublisherMiddlewareFunc](https://github.com/gojek/courier-go/blob/main/publisher.go#L32)

PublisherMiddlewareFunc functions are closures that intercept Publisher.Publish calls.

type PublisherMiddlewareFunc func(Publisher) Publisher
### func \(PublisherMiddlewareFunc\) [Middleware](https://github.com/gojek/courier-go/blob/main/publisher.go#L35)
func (pmw PublisherMiddlewareFunc) Middleware(publisher Publisher) Publisher

Middleware allows PublisherMiddlewareFunc to implement the publishMiddleware interface.

## type [QOSLevel](https://github.com/gojek/courier-go/blob/main/options.go#L10)

QOSLevel is an agreement between the sender of a message and the receiver of a message that defines the guarantee of delivery for a specific message

type QOSLevel uint8
const (
// QOSZero denotes at most once message delivery
QOSZero QOSLevel = 0
// QOSOne denotes at least once message delivery
QOSOne QOSLevel = 1
// QOSTwo denotes exactly once message delivery
QOSTwo QOSLevel = 2
)
## type [Resolver](https://github.com/gojek/courier-go/blob/main/client_resolver.go#L17-L22)

Resolver sends TCPAddress updates on channel returned by UpdateChan() channel.

type Resolver interface {
// UpdateChan returns a channel where TCPAddress updates can be received.
UpdateChan() <-chan []TCPAddress
// Done returns a channel which is closed when the Resolver is no longer running.
Done() <-chan struct{}
}
## type [Retained](https://github.com/gojek/courier-go/blob/main/options.go#L26)

Retained is an option used with Publisher.Publish call

type Retained bool
## type [StartOption](https://github.com/gojek/courier-go/blob/main/exp_starter.go#L14)

StartOption can be used to customise behaviour of ExponentialStartStrategy

type StartOption func(*startOptions)
### func [WithMaxInterval](https://github.com/gojek/courier-go/blob/main/exp_starter.go#L18)
func WithMaxInterval(interval time.Duration) StartOption

WithMaxInterval sets the maximum interval the retry logic will wait before attempting another Client.Start, Default is 30 seconds

### func [WithOnRetry](https://github.com/gojek/courier-go/blob/main/exp_starter.go#L28)
func WithOnRetry(retryFunc func(error)) StartOption

WithOnRetry sets the func which is called when there is an error in the previous Client.Start attempt

## type [Store](https://github.com/gojek/courier-go/blob/main/alias.go#L16)

Store is an interface which can be used to provide implementations for message persistence.

[IMPORTANT] When implementing a store with a shared storage (ex: redis) across multiple application instances, it should be ensured that the keys are namespaced for each application instance otherwise there will be collisions. The messages are identified based on message id from the MQTT packets, and they have values in range (0, 2^16), this coincides with max number of in-flight messages

type Store = mqtt.Store
### func [NewMemoryStore](https://github.com/gojek/courier-go/blob/main/alias.go#L21)
func NewMemoryStore() Store

NewMemoryStore returns a pointer to a new instance of mqtt.MemoryStore, the instance is not initialized and ready to use until Open() has been called on it.

## type [Subscriber](https://github.com/gojek/courier-go/blob/main/subscriber.go#L8-L14)

Subscriber defines behaviour of an MQTT subscriber that can create subscriptions.

type Subscriber interface {
// Subscribe allows to subscribe to messages from an MQTT broker
Subscribe(ctx context.Context, topic string, callback MessageHandler, opts ...Option) error

// SubscribeMultiple allows to subscribe to messages on multiple topics from an MQTT broker
SubscribeMultiple(ctx context.Context, topicsWithQos map[string]QOSLevel, callback MessageHandler) error
}
## type [SubscriberFuncs](https://github.com/gojek/courier-go/blob/main/subscriber.go#L30-L33)

SubscriberFuncs defines signature of a Subscribe function.

type SubscriberFuncs struct {
// contains filtered or unexported fields
}
### func [NewSubscriberFuncs](https://github.com/gojek/courier-go/blob/main/subscriber.go#L36-L39)
func NewSubscriberFuncs(subscribeFunc func(context.Context, string, MessageHandler, ...Option) error, subscribeMultipleFunc func(context.Context, map[string]QOSLevel, MessageHandler) error) SubscriberFuncs

NewSubscriberFuncs is a helper function to create SubscriberFuncs

### func \(SubscriberFuncs\) [Subscribe](https://github.com/gojek/courier-go/blob/main/subscriber.go#L44)
func (s SubscriberFuncs) Subscribe(ctx context.Context, topic string, callback MessageHandler, opts ...Option) error

Subscribe implements Subscriber interface on SubscriberFuncs.

### func \(SubscriberFuncs\) [SubscribeMultiple](https://github.com/gojek/courier-go/blob/main/subscriber.go#L49-L53)
func (s SubscriberFuncs) SubscribeMultiple(ctx context.Context, topicsWithQos map[string]QOSLevel, callback MessageHandler) error

SubscribeMultiple implements Subscriber interface on SubscriberFuncs.

## type [SubscriberMiddlewareFunc](https://github.com/gojek/courier-go/blob/main/subscriber.go#L22)

SubscriberMiddlewareFunc functions are closures that intercept Subscriber.Subscribe calls.

type SubscriberMiddlewareFunc func(Subscriber) Subscriber
### func \(SubscriberMiddlewareFunc\) [Middleware](https://github.com/gojek/courier-go/blob/main/subscriber.go#L25)
func (smw SubscriberMiddlewareFunc) Middleware(subscriber Subscriber) Subscriber

Middleware allows SubscriberMiddlewareFunc to implement the subscribeMiddleware interface.

## type [TCPAddress](https://github.com/gojek/courier-go/blob/main/client_resolver.go#L11-L14)

TCPAddress specifies Host and Port for remote broker

type TCPAddress struct {
Host string
Port uint16
}
## type [Unsubscriber](https://github.com/gojek/courier-go/blob/main/unsubscriber.go#L8-L11)

Unsubscriber defines behaviour of an MQTT client that can remove subscriptions.

type Unsubscriber interface {
// Unsubscribe removes any subscription to messages from an MQTT broker
Unsubscribe(ctx context.Context, topics ...string) error
}
## type [UnsubscriberFunc](https://github.com/gojek/courier-go/blob/main/unsubscriber.go#L27)

UnsubscriberFunc defines signature of a Unsubscribe function.

type UnsubscriberFunc func(context.Context, ...string) error
### func \(UnsubscriberFunc\) [Unsubscribe](https://github.com/gojek/courier-go/blob/main/unsubscriber.go#L30)
func (f UnsubscriberFunc) Unsubscribe(ctx context.Context, topics ...string) error

Unsubscribe implements Unsubscriber interface on UnsubscriberFunc.

## type [UnsubscriberMiddlewareFunc](https://github.com/gojek/courier-go/blob/main/unsubscriber.go#L19)

UnsubscriberMiddlewareFunc functions are closures that intercept Unsubscriber.Unsubscribe calls.

type UnsubscriberMiddlewareFunc func(Unsubscriber) Unsubscriber
### func \(UnsubscriberMiddlewareFunc\) [Middleware](https://github.com/gojek/courier-go/blob/main/unsubscriber.go#L22)
func (usmw UnsubscriberMiddlewareFunc) Middleware(unsubscriber Unsubscriber) Unsubscriber

Middleware allows UnsubscriberMiddlewareFunc to implement the unsubscribeMiddleware interface.

Generated by gomarkdoc

- +

SDK

courier

import "github.com/gojek/courier-go"

Package courier contains the client that can be used to interact with the courier infrastructure to publish/subscribe to messages from other clients

Index

Variables

var (
// ErrConnectTimeout indicates connection timeout while connecting to broker.
ErrConnectTimeout = errors.New("client timed out while trying to connect to the broker")
// ErrPublishTimeout indicates publish timeout.
ErrPublishTimeout = errors.New("publish timeout")
// ErrSubscribeTimeout indicates subscribe timeout.
ErrSubscribeTimeout = errors.New("subscribe timeout")
// ErrUnsubscribeTimeout indicates unsubscribe timeout.
ErrUnsubscribeTimeout = errors.New("unsubscribe timeout")
// ErrSubscribeMultipleTimeout indicates multiple subscribe timeout.
ErrSubscribeMultipleTimeout = errors.New("subscribe multiple timeout")
)
## func [ExponentialStartStrategy](https://github.com/gojek/courier-go/blob/main/exp_starter.go#L32)
func ExponentialStartStrategy(ctx context.Context, c interface{ Start() error }, opts ...StartOption)

ExponentialStartStrategy will keep attempting to call Client.Start in the background and retry on error, it will never exit unless the context used to invoke is cancelled. This will NOT stop the client, that is the responsibility of caller.

## func [Version](https://github.com/gojek/courier-go/blob/main/version.go#L4)
func Version() string

Version can be used to get the current courier library version

## func [WaitForConnection](https://github.com/gojek/courier-go/blob/main/utils.go#L10)
func WaitForConnection(c ConnectionInformer, waitFor time.Duration, tick time.Duration) bool

WaitForConnection checks if the Client is connected, it calls ConnectionInformer.IsConnected after every tick and waitFor is the maximum duration it can block. Returns true only when ConnectionInformer.IsConnected returns true

## type [Client](https://github.com/gojek/courier-go/blob/main/client.go#L17-L29)

Client allows to communicate with an MQTT broker

type Client struct {
// contains filtered or unexported fields
}
### func [NewClient](https://github.com/gojek/courier-go/blob/main/client.go#L34)
func NewClient(opts ...ClientOption) (*Client, error)

NewClient creates the Client struct with the clientOptions provided, it can return error when prometheus.DefaultRegisterer has already been used to register the collected metrics

Example

c, err := courier.NewClient(
courier.WithUsername("username"),
courier.WithPassword("password"),
courier.WithAddress("localhost", 1883),
)

if err != nil {
panic(err)
}

if err := c.Start(); err != nil {
panic(err)
}

stopCh := make(chan os.Signal, 1)
signal.Notify(stopCh, []os.Signal{os.Interrupt, syscall.SIGTERM}...)

go func() {
tick := time.NewTicker(time.Second)
for {
select {
case t := <-tick.C:
msg := map[string]interface{}{
"time": t.UnixNano(),
}
if err := c.Publish(context.Background(), "topic", msg, courier.QOSOne); err != nil {
fmt.Printf("Publish() error = %s\n", err)
} else {
fmt.Println("Publish() success")
}
case <-stopCh:
tick.Stop()
return
}
}
}()

<-stopCh
c.Stop()

### func \(\*Client\) [IsConnected](https://github.com/gojek/courier-go/blob/main/client.go#L59)
func (c *Client) IsConnected() (online bool)

IsConnected checks whether the client is connected to the broker

### func \(\*Client\) [Publish](https://github.com/gojek/courier-go/blob/main/client_publish.go#L11)
func (c *Client) Publish(ctx context.Context, topic string, message interface{}, opts ...Option) error

Publish allows to publish messages to an MQTT broker

### func \(\*Client\) [Run](https://github.com/gojek/courier-go/blob/main/client.go#L110)
func (c *Client) Run(ctx context.Context) error

Run will start running the Client. This makes Client compatible with github.com/gojekfarm/xrun package. https://pkg.go.dev/github.com/gojekfarm/xrun

### func \(\*Client\) [Start](https://github.com/gojek/courier-go/blob/main/client.go#L68)
func (c *Client) Start() (err error)

Start will attempt to connect to the broker.

### func \(\*Client\) [Stop](https://github.com/gojek/courier-go/blob/main/client.go#L102)
func (c *Client) Stop()

Stop will disconnect from the broker and finish up any pending work on internal communication workers. This can only block until the period configured with the ClientOption WithGracefulShutdownPeriod.

### func \(\*Client\) [Subscribe](https://github.com/gojek/courier-go/blob/main/client_subscribe.go#L11)
func (c *Client) Subscribe(ctx context.Context, topic string, callback MessageHandler, opts ...Option) error

Subscribe allows to subscribe to messages from an MQTT broker

### func \(\*Client\) [SubscribeMultiple](https://github.com/gojek/courier-go/blob/main/client_subscribe.go#L16-L20)
func (c *Client) SubscribeMultiple(ctx context.Context, topicsWithQos map[string]QOSLevel, callback MessageHandler) error

SubscribeMultiple allows to subscribe to messages on multiple topics from an MQTT broker

### func \(\*Client\) [Unsubscribe](https://github.com/gojek/courier-go/blob/main/client_unsubscribe.go#L10)
func (c *Client) Unsubscribe(ctx context.Context, topics ...string) error

Unsubscribe removes any subscription to messages from an MQTT broker

### func \(\*Client\) [UsePublisherMiddleware](https://github.com/gojek/courier-go/blob/main/client_publish.go#L18)
func (c *Client) UsePublisherMiddleware(mwf ...PublisherMiddlewareFunc)

UsePublisherMiddleware appends a PublisherMiddlewareFunc to the chain. Middleware can be used to intercept or otherwise modify, process or skip messages. They are executed in the order that they are applied to the Client.

### func \(\*Client\) [UseSubscriberMiddleware](https://github.com/gojek/courier-go/blob/main/client_subscribe.go#L27)
func (c *Client) UseSubscriberMiddleware(mwf ...SubscriberMiddlewareFunc)

UseSubscriberMiddleware appends a SubscriberMiddlewareFunc to the chain. Middleware can be used to intercept or otherwise modify, process or skip subscriptions. They are executed in the order that they are applied to the Client.

### func \(\*Client\) [UseUnsubscriberMiddleware](https://github.com/gojek/courier-go/blob/main/client_unsubscribe.go#L17)
func (c *Client) UseUnsubscriberMiddleware(mwf ...UnsubscriberMiddlewareFunc)

UseUnsubscriberMiddleware appends a UnsubscriberMiddlewareFunc to the chain. Middleware can be used to intercept or otherwise modify, process or skip subscriptions. They are executed in the order that they are applied to the Client.

## type [ClientOption](https://github.com/gojek/courier-go/blob/main/client_options.go#L12)

ClientOption allows to configure the behaviour of a Client.

type ClientOption interface {
// contains filtered or unexported methods
}
### func [WithAddress](https://github.com/gojek/courier-go/blob/main/client_options.go#L115)
func WithAddress(host string, port uint16) ClientOption

WithAddress sets the broker address to be used. To establish a TLS connection, use WithTLS Option along with this. Default values for hostname is "127.0.0.1" and for port is 1883.

### func [WithAutoReconnect](https://github.com/gojek/courier-go/blob/main/client_options.go#L45)
func WithAutoReconnect(autoReconnect bool) ClientOption

WithAutoReconnect sets whether the automatic reconnection logic should be used when the connection is lost, even if disabled the WithOnConnectionLost is still called.

### func [WithCleanSession](https://github.com/gojek/courier-go/blob/main/client_options.go#L57)
func WithCleanSession(cleanSession bool) ClientOption

WithCleanSession will set the "clean session" flag in the connect message when this client connects to an MQTT broker. By setting this flag, you are indicating that no messages saved by the broker for this client should be delivered. Any messages that were going to be sent by this client before disconnecting but didn't, will not be sent upon connecting to the broker.

### func [WithClientID](https://github.com/gojek/courier-go/blob/main/client_options.go#L16)
func WithClientID(clientID string) ClientOption

WithClientID sets the clientID to be used while connecting to an MQTT broker. According to the MQTT v3.1 specification, a client id must be no longer than 23 characters.

### func [WithConnectTimeout](https://github.com/gojek/courier-go/blob/main/client_options.go#L134)
func WithConnectTimeout(duration time.Duration) ClientOption

WithConnectTimeout limits how long the client will wait when trying to open a connection to an MQTT server before timing out. A duration of 0 never times out. Default 15 seconds.

### func [WithCustomDecoder](https://github.com/gojek/courier-go/blob/main/client_options.go#L176)
func WithCustomDecoder(decoderFunc DecoderFunc) ClientOption

WithCustomDecoder allows to decode message bytes into the desired object.

### func [WithCustomEncoder](https://github.com/gojek/courier-go/blob/main/client_options.go#L173)
func WithCustomEncoder(encoderFunc EncoderFunc) ClientOption

WithCustomEncoder allows to transform objects into the desired message bytes.

### func [WithExponentialStartOptions](https://github.com/gojek/courier-go/blob/main/client_options.go#L188)
func WithExponentialStartOptions(options ...StartOption) ClientOption

WithExponentialStartOptions configures the client to use ExponentialStartStrategy along with the passed StartOption(s) when using the Client.Run method.

### func [WithGracefulShutdownPeriod](https://github.com/gojek/courier-go/blob/main/client_options.go#L158)
func WithGracefulShutdownPeriod(duration time.Duration) ClientOption

WithGracefulShutdownPeriod sets the limit that is allowed for existing work to be completed.

### func [WithKeepAlive](https://github.com/gojek/courier-go/blob/main/client_options.go#L125)
func WithKeepAlive(duration time.Duration) ClientOption

WithKeepAlive will set the amount of time (in seconds) that the client should wait before sending a PING request to the broker. This will allow the client to know that a connection has not been lost with the server.

### func [WithMaintainOrder](https://github.com/gojek/courier-go/blob/main/client_options.go#L71)
func WithMaintainOrder(maintainOrder bool) ClientOption

WithMaintainOrder will set the message routing to guarantee order within each QoS level. By default, this value is true. If set to false (recommended), this flag indicates that messages can be delivered asynchronously from the client to the application and possibly arrive out of order. Specifically, the message handler is called in its own go routine. Note that setting this to true does not guarantee in-order delivery (this is subject to broker settings like "max_inflight_messages=1") and if true then MessageHandler callback must not block.

### func [WithMaxReconnectInterval](https://github.com/gojek/courier-go/blob/main/client_options.go#L151)
func WithMaxReconnectInterval(duration time.Duration) ClientOption

WithMaxReconnectInterval sets the maximum time that will be waited between reconnection attempts. when connection is lost

### func [WithOnConnect](https://github.com/gojek/courier-go/blob/main/client_options.go#L79)
func WithOnConnect(handler OnConnectHandler) ClientOption

WithOnConnect will set the OnConnectHandler callback to be called when the client is connected. Both at initial connection time and upon automatic reconnect.

### func [WithOnConnectionLost](https://github.com/gojek/courier-go/blob/main/client_options.go#L87)
func WithOnConnectionLost(handler OnConnectionLostHandler) ClientOption

WithOnConnectionLost will set the OnConnectionLostHandler callback to be executed in the case where the client unexpectedly loses connection with the MQTT broker.

### func [WithOnReconnect](https://github.com/gojek/courier-go/blob/main/client_options.go#L95)
func WithOnReconnect(handler OnReconnectHandler) ClientOption

WithOnReconnect sets the OnReconnectHandler callback to be executed prior to the client attempting a reconnect to the MQTT broker.

### func [WithPassword](https://github.com/gojek/courier-go/blob/main/client_options.go#L30)
func WithPassword(password string) ClientOption

WithPassword sets the password to be used while connecting to an MQTT broker.

### func [WithPersistence](https://github.com/gojek/courier-go/blob/main/client_options.go#L166)
func WithPersistence(store Store) ClientOption

WithPersistence allows to configure the store to be used by broker Default persistence is in-memory persistence with mqtt.MemoryStore

### func [WithResolver](https://github.com/gojek/courier-go/blob/main/client_resolver.go#L25)
func WithResolver(resolver Resolver) ClientOption

WithResolver sets the specified Resolver.

### func [WithTCPAddress](https://github.com/gojek/courier-go/blob/main/client_options.go#L106)
func WithTCPAddress(host string, port uint16) ClientOption

WithTCPAddress sets the broker address to be used. Default values for hostname is "127.0.0.1" and for port is 1883.

Deprecated: This Option used to work with plain TCP connections, it's now possible to use TLS with WithAddress and WithTLS combination.

### func [WithTLS](https://github.com/gojek/courier-go/blob/main/client_options.go#L37)
func WithTLS(tlsConfig *tls.Config) ClientOption

WithTLS sets the TLs configuration to be used while connecting to an MQTT broker.

### func [WithUseBase64Decoder](https://github.com/gojek/courier-go/blob/main/client_options.go#L180)
func WithUseBase64Decoder() ClientOption

WithUseBase64Decoder configures a json decoder with a base64.StdEncoding wrapped decoder which decodes base64 encoded message bytes into the passed object.

### func [WithUsername](https://github.com/gojek/courier-go/blob/main/client_options.go#L23)
func WithUsername(username string) ClientOption

WithUsername sets the username to be used while connecting to an MQTT broker.

### func [WithWriteTimeout](https://github.com/gojek/courier-go/blob/main/client_options.go#L143)
func WithWriteTimeout(duration time.Duration) ClientOption

WithWriteTimeout limits how long the client will wait when trying to publish, subscribe or unsubscribe on topic when a context deadline is not set while calling Publisher.Publish, Subscriber.Subscribe, Subscriber.SubscribeMultiple or Unsubscriber.Unsubscribe.

## type [ConnectionInformer](https://github.com/gojek/courier-go/blob/main/interface.go#L13-L16)

ConnectionInformer can be used to get information about the connection

type ConnectionInformer interface {
// IsConnected checks whether the client is connected to the broker
IsConnected() bool
}
## type [Decoder](https://github.com/gojek/courier-go/blob/main/decoder.go#L16-L19)

Decoder helps to decode message bytes into the desired object

type Decoder interface {
// Decode decodes message bytes into the passed object
Decode(v interface{}) error
}
### func [DefaultDecoderFunc](https://github.com/gojek/courier-go/blob/main/decoder.go#L22)
func DefaultDecoderFunc(_ context.Context, r io.Reader) Decoder

DefaultDecoderFunc is a DecoderFunc that uses a json.Decoder as the Decoder.

## type [DecoderFunc](https://github.com/gojek/courier-go/blob/main/decoder.go#L13)

DecoderFunc is used to create a Decoder from io.Reader stream of message bytes before calling MessageHandler; the context.Context value may be used to select appropriate Decoder.

type DecoderFunc func(context.Context, io.Reader) Decoder
## type [Encoder](https://github.com/gojek/courier-go/blob/main/encoder.go#L14-L17)

Encoder helps in transforming objects to message bytes

type Encoder interface {
// Encode takes any object and encodes it into bytes
Encode(v interface{}) error
}
### func [DefaultEncoderFunc](https://github.com/gojek/courier-go/blob/main/encoder.go#L20)
func DefaultEncoderFunc(_ context.Context, w io.Writer) Encoder

DefaultEncoderFunc is a EncoderFunc that uses a json.Encoder as the Encoder.

## type [EncoderFunc](https://github.com/gojek/courier-go/blob/main/encoder.go#L11)

EncoderFunc is used to create an Encoder from io.Writer; the context.Context value may be used to select appropriate Encoder.

type EncoderFunc func(context.Context, io.Writer) Encoder
## type [Message](https://github.com/gojek/courier-go/blob/main/message.go#L4-L12)

Message represents the entity that is being relayed via the courier MQTT brokers from Publisher(s) to Subscriber(s).

type Message struct {
ID int
Topic string
Duplicate bool
Retained bool
QoS QOSLevel
// contains filtered or unexported fields
}
### func [NewMessageWithDecoder](https://github.com/gojek/courier-go/blob/main/message.go#L15-L17)
func NewMessageWithDecoder(payloadDecoder Decoder) *Message

NewMessageWithDecoder is a helper to create Message, ideally payloadDecoder should not be mutated once created.

### func \(\*Message\) [DecodePayload](https://github.com/gojek/courier-go/blob/main/message.go#L24)
func (m *Message) DecodePayload(v interface{}) error

DecodePayload can decode the message payload bytes into the desired object.

## type [MessageHandler](https://github.com/gojek/courier-go/blob/main/types.go#L24)

MessageHandler is the type that all callbacks being passed to Subscriber must satisfy.

type MessageHandler func(context.Context, PubSub, *Message)
## type [OnConnectHandler](https://github.com/gojek/courier-go/blob/main/types.go#L10)

OnConnectHandler is a callback that is called when the client state changes from disconnected to connected. Both at initial connection and on reconnection

type OnConnectHandler func(PubSub)
## type [OnConnectionLostHandler](https://github.com/gojek/courier-go/blob/main/types.go#L16)

OnConnectionLostHandler is a callback type which can be set to be executed upon an unintended disconnection from the MQTT broker. Disconnects caused by calling Disconnect or ForceDisconnect will not cause an WithOnConnectionLost callback to execute.

type OnConnectionLostHandler func(error)
## type [OnReconnectHandler](https://github.com/gojek/courier-go/blob/main/types.go#L20)

OnReconnectHandler is invoked prior to reconnecting after the initial connection is lost

type OnReconnectHandler func(PubSub)
## type [Option](https://github.com/gojek/courier-go/blob/main/options.go#L4-L6)

Option changes behaviour of Publisher.Publish, Subscriber.Subscribe calls.

type Option interface {
// contains filtered or unexported methods
}
## type [PubSub](https://github.com/gojek/courier-go/blob/main/interface.go#L5-L10)

PubSub exposes all the operational functionalities of Client with Publisher, Subscriber, Unsubscriber and ConnectionInformer

type PubSub interface {
Publisher
Subscriber
Unsubscriber
ConnectionInformer
}
## type [Publisher](https://github.com/gojek/courier-go/blob/main/publisher.go#L8-L11)

Publisher defines behaviour of an MQTT publisher that can send messages.

type Publisher interface {
// Publish allows to publish messages to an MQTT broker
Publish(ctx context.Context, topic string, message interface{}, options ...Option) error
}
## type [PublisherFunc](https://github.com/gojek/courier-go/blob/main/publisher.go#L14)

PublisherFunc defines signature of a Publish function.

type PublisherFunc func(context.Context, string, interface{}, ...Option) error
### func \(PublisherFunc\) [Publish](https://github.com/gojek/courier-go/blob/main/publisher.go#L17-L22)
func (f PublisherFunc) Publish(ctx context.Context, topic string, message interface{}, opts ...Option) error

Publish implements Publisher interface on PublisherFunc.

## type [PublisherMiddlewareFunc](https://github.com/gojek/courier-go/blob/main/publisher.go#L32)

PublisherMiddlewareFunc functions are closures that intercept Publisher.Publish calls.

type PublisherMiddlewareFunc func(Publisher) Publisher
### func \(PublisherMiddlewareFunc\) [Middleware](https://github.com/gojek/courier-go/blob/main/publisher.go#L35)
func (pmw PublisherMiddlewareFunc) Middleware(publisher Publisher) Publisher

Middleware allows PublisherMiddlewareFunc to implement the publishMiddleware interface.

## type [QOSLevel](https://github.com/gojek/courier-go/blob/main/options.go#L10)

QOSLevel is an agreement between the sender of a message and the receiver of a message that defines the guarantee of delivery for a specific message

type QOSLevel uint8
const (
// QOSZero denotes at most once message delivery
QOSZero QOSLevel = 0
// QOSOne denotes at least once message delivery
QOSOne QOSLevel = 1
// QOSTwo denotes exactly once message delivery
QOSTwo QOSLevel = 2
)
## type [Resolver](https://github.com/gojek/courier-go/blob/main/client_resolver.go#L17-L22)

Resolver sends TCPAddress updates on channel returned by UpdateChan() channel.

type Resolver interface {
// UpdateChan returns a channel where TCPAddress updates can be received.
UpdateChan() <-chan []TCPAddress
// Done returns a channel which is closed when the Resolver is no longer running.
Done() <-chan struct{}
}
## type [Retained](https://github.com/gojek/courier-go/blob/main/options.go#L26)

Retained is an option used with Publisher.Publish call

type Retained bool
## type [StartOption](https://github.com/gojek/courier-go/blob/main/exp_starter.go#L9)

StartOption can be used to customise behaviour of ExponentialStartStrategy

type StartOption func(*startOptions)
### func [WithMaxInterval](https://github.com/gojek/courier-go/blob/main/exp_starter.go#L13)
func WithMaxInterval(interval time.Duration) StartOption

WithMaxInterval sets the maximum interval the retry logic will wait before attempting another Client.Start, Default is 30 seconds

### func [WithOnRetry](https://github.com/gojek/courier-go/blob/main/exp_starter.go#L23)
func WithOnRetry(retryFunc func(error)) StartOption

WithOnRetry sets the func which is called when there is an error in the previous Client.Start attempt

## type [Store](https://github.com/gojek/courier-go/blob/main/alias.go#L16)

Store is an interface which can be used to provide implementations for message persistence.

[IMPORTANT] When implementing a store with a shared storage (ex: redis) across multiple application instances, it should be ensured that the keys are namespaced for each application instance otherwise there will be collisions. The messages are identified based on message id from the MQTT packets, and they have values in range (0, 2^16), this coincides with max number of in-flight messages

type Store = mqtt.Store
### func [NewMemoryStore](https://github.com/gojek/courier-go/blob/main/alias.go#L21)
func NewMemoryStore() Store

NewMemoryStore returns a pointer to a new instance of mqtt.MemoryStore, the instance is not initialized and ready to use until Open() has been called on it.

## type [Subscriber](https://github.com/gojek/courier-go/blob/main/subscriber.go#L8-L14)

Subscriber defines behaviour of an MQTT subscriber that can create subscriptions.

type Subscriber interface {
// Subscribe allows to subscribe to messages from an MQTT broker
Subscribe(ctx context.Context, topic string, callback MessageHandler, opts ...Option) error

// SubscribeMultiple allows to subscribe to messages on multiple topics from an MQTT broker
SubscribeMultiple(ctx context.Context, topicsWithQos map[string]QOSLevel, callback MessageHandler) error
}
## type [SubscriberFuncs](https://github.com/gojek/courier-go/blob/main/subscriber.go#L30-L33)

SubscriberFuncs defines signature of a Subscribe function.

type SubscriberFuncs struct {
// contains filtered or unexported fields
}
### func [NewSubscriberFuncs](https://github.com/gojek/courier-go/blob/main/subscriber.go#L36-L39)
func NewSubscriberFuncs(subscribeFunc func(context.Context, string, MessageHandler, ...Option) error, subscribeMultipleFunc func(context.Context, map[string]QOSLevel, MessageHandler) error) SubscriberFuncs

NewSubscriberFuncs is a helper function to create SubscriberFuncs

### func \(SubscriberFuncs\) [Subscribe](https://github.com/gojek/courier-go/blob/main/subscriber.go#L44)
func (s SubscriberFuncs) Subscribe(ctx context.Context, topic string, callback MessageHandler, opts ...Option) error

Subscribe implements Subscriber interface on SubscriberFuncs.

### func \(SubscriberFuncs\) [SubscribeMultiple](https://github.com/gojek/courier-go/blob/main/subscriber.go#L49-L53)
func (s SubscriberFuncs) SubscribeMultiple(ctx context.Context, topicsWithQos map[string]QOSLevel, callback MessageHandler) error

SubscribeMultiple implements Subscriber interface on SubscriberFuncs.

## type [SubscriberMiddlewareFunc](https://github.com/gojek/courier-go/blob/main/subscriber.go#L22)

SubscriberMiddlewareFunc functions are closures that intercept Subscriber.Subscribe calls.

type SubscriberMiddlewareFunc func(Subscriber) Subscriber
### func \(SubscriberMiddlewareFunc\) [Middleware](https://github.com/gojek/courier-go/blob/main/subscriber.go#L25)
func (smw SubscriberMiddlewareFunc) Middleware(subscriber Subscriber) Subscriber

Middleware allows SubscriberMiddlewareFunc to implement the subscribeMiddleware interface.

## type [TCPAddress](https://github.com/gojek/courier-go/blob/main/client_resolver.go#L11-L14)

TCPAddress specifies Host and Port for remote broker

type TCPAddress struct {
Host string
Port uint16
}
## type [Unsubscriber](https://github.com/gojek/courier-go/blob/main/unsubscriber.go#L8-L11)

Unsubscriber defines behaviour of an MQTT client that can remove subscriptions.

type Unsubscriber interface {
// Unsubscribe removes any subscription to messages from an MQTT broker
Unsubscribe(ctx context.Context, topics ...string) error
}
## type [UnsubscriberFunc](https://github.com/gojek/courier-go/blob/main/unsubscriber.go#L27)

UnsubscriberFunc defines signature of a Unsubscribe function.

type UnsubscriberFunc func(context.Context, ...string) error
### func \(UnsubscriberFunc\) [Unsubscribe](https://github.com/gojek/courier-go/blob/main/unsubscriber.go#L30)
func (f UnsubscriberFunc) Unsubscribe(ctx context.Context, topics ...string) error

Unsubscribe implements Unsubscriber interface on UnsubscriberFunc.

## type [UnsubscriberMiddlewareFunc](https://github.com/gojek/courier-go/blob/main/unsubscriber.go#L19)

UnsubscriberMiddlewareFunc functions are closures that intercept Unsubscriber.Unsubscribe calls.

type UnsubscriberMiddlewareFunc func(Unsubscriber) Unsubscriber
### func \(UnsubscriberMiddlewareFunc\) [Middleware](https://github.com/gojek/courier-go/blob/main/unsubscriber.go#L22)
func (usmw UnsubscriberMiddlewareFunc) Middleware(unsubscriber Unsubscriber) Unsubscriber

Middleware allows UnsubscriberMiddlewareFunc to implement the unsubscribeMiddleware interface.

Generated by gomarkdoc

+ \ No newline at end of file diff --git a/docs/sdk/otelcourier/index.html b/docs/sdk/otelcourier/index.html index 819f322..36f82d4 100644 --- a/docs/sdk/otelcourier/index.html +++ b/docs/sdk/otelcourier/index.html @@ -4,13 +4,13 @@ otelcourier | Courier Go - +

otelcourier

otelcourier

import "github.com/gojek/courier-go/otelcourier"

Package otelcourier instruments the github.com/gojek/courier-go package.

Index

Constants

const (
// MQTTTopic is the attribute key for tracing message topic
MQTTTopic = attribute.Key("mqtt.topic")
// MQTTQoS is the attribute key for tracing message qos
MQTTQoS = attribute.Key("mqtt.qos")
// MQTTTopicWithQoS is the attribute key for tracing message topic and qos together
MQTTTopicWithQoS = attribute.Key("mqtt.topicwithqos")
// MQTTRetained is the attribute key for tracing message retained flag
MQTTRetained = attribute.Key("mqtt.retained")
)
## func [DisableCallbackTracing](https://github.com/gojek/courier-go/blob/main/otelcourier/options.go#L59)
func DisableCallbackTracing(opts *traceOptions)

DisableCallbackTracing disables implicit tracing on subscription callbacks.

## func [DisablePublisherTracing](https://github.com/gojek/courier-go/blob/main/otelcourier/options.go#L62)
func DisablePublisherTracing(opts *traceOptions)

DisablePublisherTracing disables courier.Publisher tracing.

## func [DisableSubscriberTracing](https://github.com/gojek/courier-go/blob/main/otelcourier/options.go#L65)
func DisableSubscriberTracing(opts *traceOptions)

DisableSubscriberTracing disables courier.Subscriber tracing.

## func [DisableUnsubscriberTracing](https://github.com/gojek/courier-go/blob/main/otelcourier/options.go#L68)
func DisableUnsubscriberTracing(opts *traceOptions)

DisableUnsubscriberTracing disables courier.Unsubscriber tracing.

## type [Option](https://github.com/gojek/courier-go/blob/main/otelcourier/options.go#L30)

Option helps configure trace options.

type Option func(*traceOptions)
### func [WithTextMapCarrierExtractFunc](https://github.com/gojek/courier-go/blob/main/otelcourier/options.go#L54)
func WithTextMapCarrierExtractFunc(fn func(context.Context) propagation.TextMapCarrier) Option

WithTextMapCarrierExtractFunc is used to specify the function which should be used to extract propagation.TextMapCarrier from the ongoing context.Context.

### func [WithTextMapPropagator](https://github.com/gojek/courier-go/blob/main/otelcourier/options.go#L48)
func WithTextMapPropagator(propagator propagation.TextMapPropagator) Option

WithTextMapPropagator specifies the propagator to use for extracting/injecting key-value texts. If none is specified, the global provider is used.

### func [WithTracerProvider](https://github.com/gojek/courier-go/blob/main/otelcourier/options.go#L42)
func WithTracerProvider(provider oteltrace.TracerProvider) Option

WithTracerProvider specifies a tracer provider to use for creating a tracer. If none is specified, the global provider is used.

## type [Tracer](https://github.com/gojek/courier-go/blob/main/otelcourier/trace.go#L17-L23)

Tracer implements tracing abilities using OpenTelemetry SDK.

type Tracer struct {
// contains filtered or unexported fields
}
### func [NewTracer](https://github.com/gojek/courier-go/blob/main/otelcourier/trace.go#L26)
func NewTracer(service string, opts ...Option) *Tracer

NewTracer creates a new Tracer with Option(s).

Example

package main

import (
"context"
"os"
"os/signal"
"syscall"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/sdk/trace"

courier "github.com/gojek/courier-go"
"github.com/gojek/courier-go/otelcourier"
)

func main() {
tp := trace.NewTracerProvider()
defer tp.Shutdown(context.Background())

otel.SetTracerProvider(tp)

c, _ := courier.NewClient()
otelcourier.NewTracer("service-name").ApplyTraceMiddlewares(c)

if err := c.Start(); err != nil {
panic(err)
}

stopCh := make(chan os.Signal, 1)
signal.Notify(stopCh, []os.Signal{os.Interrupt, syscall.SIGTERM}...)

if err := c.Publish(
context.Background(), "test-topic", "message", courier.QOSOne); err != nil {
panic(err)
}
<-stopCh

c.Stop()
}

### func \(\*Tracer\) [ApplyTraceMiddlewares](https://github.com/gojek/courier-go/blob/main/otelcourier/trace.go#L49)
func (t *Tracer) ApplyTraceMiddlewares(c *courier.Client)

ApplyTraceMiddlewares will instrument all the operations of a courier.Client instance according to Option(s) used.

### func \(\*Tracer\) [PublisherMiddleware](https://github.com/gojek/courier-go/blob/main/otelcourier/publish.go#L20)
func (t *Tracer) PublisherMiddleware(next courier.Publisher) courier.Publisher

PublisherMiddleware is a courier.PublisherMiddlewareFunc for tracing publish calls.

### func \(\*Tracer\) [SubscriberMiddleware](https://github.com/gojek/courier-go/blob/main/otelcourier/subscribe.go#L25)
func (t *Tracer) SubscriberMiddleware(next courier.Subscriber) courier.Subscriber

SubscriberMiddleware is a courier.SubscriberMiddlewareFunc for tracing subscribe calls.

### func \(\*Tracer\) [UnsubscriberMiddleware](https://github.com/gojek/courier-go/blob/main/otelcourier/unsubscribe.go#L19)
func (t *Tracer) UnsubscriberMiddleware(next courier.Unsubscriber) courier.Unsubscriber

UnsubscriberMiddleware is a courier.UnsubscriberMiddlewareFunc for tracing unsubscribe calls.

Generated by gomarkdoc

- + \ No newline at end of file diff --git a/docs/sdk/xds/backoff/index.html b/docs/sdk/xds/backoff/index.html index 86d2187..feab289 100644 --- a/docs/sdk/xds/backoff/index.html +++ b/docs/sdk/xds/backoff/index.html @@ -4,13 +4,13 @@ backoff | Courier Go - +

backoff

backoff

import "github.com/gojek/courier-go/xds/backoff"

Package backoff provides exponential backoff capabilities

Index

Variables

DefaultExponential is an exponential backoff implementation using the default values for all the configurable knobs defined in https://github.com/grpc/grpc/blob/master/doc/connection-backoff.md.
var DefaultExponential = Exponential{Config: grpcbackoff.DefaultConfig}
## type [Exponential](https://github.com/gojek/courier-go/blob/main/xds/backoff/backoff.go#L27-L30)

Exponential implements exponential backoff algorithm as defined in https://github.com/grpc/grpc/blob/master/doc/connection-backoff.md.

type Exponential struct {
// Config contains all options to configure the backoff algorithm.
Config grpcbackoff.Config
}
### func \(Exponential\) [Backoff](https://github.com/gojek/courier-go/blob/main/xds/backoff/backoff.go#L34)
func (bc Exponential) Backoff(retries int) time.Duration

Backoff returns the amount of time to wait before the next retry given the number of retries.

## type [Strategy](https://github.com/gojek/courier-go/blob/main/xds/backoff/backoff.go#L12-L16)

Strategy defines the methodology for backing off after a grpc connection failure.

type Strategy interface {
// Backoff returns the amount of time to wait before the next retry given
// the number of consecutive failures.
Backoff(retries int) time.Duration
}

Generated by gomarkdoc

- + \ No newline at end of file diff --git a/docs/sdk/xds/bootstrap/index.html b/docs/sdk/xds/bootstrap/index.html index d723446..e820d8c 100644 --- a/docs/sdk/xds/bootstrap/index.html +++ b/docs/sdk/xds/bootstrap/index.html @@ -4,13 +4,13 @@ bootstrap | Courier Go - +

bootstrap

bootstrap

import "github.com/gojek/courier-go/xds/bootstrap"

Package bootstrap provides bootstrap config loading capabilities to xds client

Index

## type [Config](https://github.com/gojek/courier-go/blob/main/xds/bootstrap/bootstrap.go#L55-L58)

Config provides the xDS client with several key bits of information that it requires in its interaction with the management server. The Config is initialized from the bootstrap file.

type Config struct {
// XDSServer is the management server to connect to.
XDSServer *ServerConfig `json:"xds_server"`
}
### func [NewConfig](https://github.com/gojek/courier-go/blob/main/xds/bootstrap/bootstrap.go#L63)
func NewConfig() (*Config, error)

NewConfig returns a bootstrap config after reading the BootstrapConfig from the file specified by COURIER_XDS_BOOTSTRAP env var or the base64 encoded string in COURIER_XDS_BOOTSTRAP_CONFIG_BASE64 var.

### func [NewConfigFromContents](https://github.com/gojek/courier-go/blob/main/xds/bootstrap/bootstrap.go#L73)
func NewConfigFromContents(data []byte) (*Config, error)

NewConfigFromContents returns a bootstrap config after reading the BootstrapConfig from data.

## type [ServerConfig](https://github.com/gojek/courier-go/blob/main/xds/bootstrap/bootstrap.go#L95-L108)

ServerConfig contains the configuration to connect to a server, including URI, creds, and transport API version (e.g. v2 or v3).

type ServerConfig struct {
// ServerURI is the management server to connect to.
//
// The bootstrap file contains an ordered list of xDS servers to contact for
// this authority. The first one is picked.
ServerURI string `json:"server_uri"`
// NodeProto contains the Node proto to be used in xDS requests. The actual
// type depends on the transport protocol version used.
//
// Note that it's specified in the bootstrap globally for all the servers,
// but we keep it in each server config so that its type (e.g. *v3pb.Node)
// is consistent with the transport API version.
NodeProto proto.Message
}
### func \(ServerConfig\) [MarshalJSON](https://github.com/gojek/courier-go/blob/main/xds/bootstrap/bootstrap.go#L124)
func (sc ServerConfig) MarshalJSON() ([]byte, error)

MarshalJSON marshals the ServerConfig to json.

### func \(\*ServerConfig\) [String](https://github.com/gojek/courier-go/blob/main/xds/bootstrap/bootstrap.go#L119)
func (sc *ServerConfig) String() string

String returns the string representation of the ServerConfig.

This string representation will be used as map keys in federation (`map[ServerConfig]authority`), so that the xDS ClientConn and stream will be shared by authorities with different names but the same server config.

It covers (almost) all the fields so the string can represent the config content. It doesn't cover NodeProto because NodeProto isn't used by federation.

### func \(\*ServerConfig\) [UnmarshalJSON](https://github.com/gojek/courier-go/blob/main/xds/bootstrap/bootstrap.go#L135)
func (sc *ServerConfig) UnmarshalJSON(data []byte) error

UnmarshalJSON takes the json data (a server) and unmarshals it to the struct.

Generated by gomarkdoc

- + \ No newline at end of file diff --git a/docs/sdk/xds/index.html b/docs/sdk/xds/index.html index 429781b..34512ca 100644 --- a/docs/sdk/xds/index.html +++ b/docs/sdk/xds/index.html @@ -4,13 +4,13 @@ xDS | Courier Go - +

xDS

xds

import "github.com/gojek/courier-go/xds"

Package xds contains the client that can be used to interact with the management server to receive address updates for subscribed clusters

Index

## type [Client](https://github.com/gojek/courier-go/blob/main/xds/client.go#L69-L80)

Client performs the actual ADS RPCs using the ADS v3 API. It creates an ADS stream on which the xdsTarget resources are received.

type Client struct {
// contains filtered or unexported fields
}
### func [NewClient](https://github.com/gojek/courier-go/blob/main/xds/client.go#L40)
func NewClient(opts Options) *Client

NewClient returns a new ADS client stream using the *grpc.ClientConn provided.

### func \(\*Client\) [Done](https://github.com/gojek/courier-go/blob/main/xds/client.go#L88)
func (c *Client) Done() <-chan struct{}

Done returns a channel which is closed when the run loop stops due to context expiry

### func \(\*Client\) [Receive](https://github.com/gojek/courier-go/blob/main/xds/client.go#L83)
func (c *Client) Receive() <-chan []*v3endpointpb.ClusterLoadAssignment

Receive returns a channel where ClusterLoadAssignment resource updates can be received

### func \(\*Client\) [Start](https://github.com/gojek/courier-go/blob/main/xds/client.go#L93)
func (c *Client) Start(ctx context.Context) error

Start will wait updates from control plane, it is non-blocking

## type [Options](https://github.com/gojek/courier-go/blob/main/xds/client.go#L31-L37)

Options specifies options to be provided for initialising the xds client

type Options struct {
XDSTarget string
NodeProto *v3corepb.Node
ClientConn grpc.ClientConnInterface
BackoffStrategy backoff.Strategy
Logger log.Logger
}
## type [Resolver](https://github.com/gojek/courier-go/blob/main/xds/resolver.go#L17-L20)

Resolver sends updates to via the channel returned by UpdateChan()

type Resolver struct {
// contains filtered or unexported fields
}
### func [NewResolver](https://github.com/gojek/courier-go/blob/main/xds/resolver.go#L23)
func NewResolver(rc clusterUpdateReceiver) *Resolver

NewResolver returns a *Resolver that uses rc to receive cluster updates

Example

cfg, err := bootstrap.NewConfigFromContents([]byte(`{
"xds_server": {
"server_uri": "localhost:9100",
"node": {
"id": "52fdfc07-2182-454f-963f-5f0f9a621d72",
"cluster": "cluster",
"metadata": {
"TRAFFICDIRECTOR_GCP_PROJECT_NUMBER": "123456789012345",
"TRAFFICDIRECTOR_NETWORK_NAME": "thedefault"
},
"locality": {
"zone": "uscentral-5"
}
}
}
}`,
))
if err != nil {
panic(err)
}

ctx, _ := signal.NotifyContext(context.Background(), os.Kill, os.Interrupt)

cc, err := grpc.DialContext(ctx, cfg.XDSServer.ServerURI, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
panic(err)
}

xdsClient := xds.NewClient(xds.Options{
XDSTarget: "xds:///broker.domain",
NodeProto: cfg.XDSServer.NodeProto.(*corev3.Node),
ClientConn: cc,
BackoffStrategy: &backoff.DefaultExponential,
})

if err := xdsClient.Start(ctx); err != nil {
panic(err)
}

r := xds.NewResolver(xdsClient)

c, err := courier.NewClient(courier.WithResolver(r))
if err != nil {
panic(err)
}

if err := c.Start(); err != nil {
panic(err)
}

<-ctx.Done()

### func \(\*Resolver\) [Done](https://github.com/gojek/courier-go/blob/main/xds/resolver.go#L40)
func (r *Resolver) Done() <-chan struct{}

Done returns a channel which is closed when the underlying clusterUpdateReceiver is marked as done

### func \(\*Resolver\) [UpdateChan](https://github.com/gojek/courier-go/blob/main/xds/resolver.go#L35)
func (r *Resolver) UpdateChan() <-chan []courier.TCPAddress

UpdateChan returns a channel where []courier.TCPAddress can be received

Generated by gomarkdoc

- + \ No newline at end of file diff --git a/docs/sdk/xds/log/index.html b/docs/sdk/xds/log/index.html index e18d892..45c99d3 100644 --- a/docs/sdk/xds/log/index.html +++ b/docs/sdk/xds/log/index.html @@ -4,13 +4,13 @@ log | Courier Go - +

log

log

import "github.com/gojek/courier-go/xds/log"

Package log provides logger interface for usage inside xds client

Index

## type [Logger](https://github.com/gojek/courier-go/blob/main/xds/log/logger.go#L4-L11)

Logger is used to log messages of info, error and debug levels

type Logger interface {
// Info is used to log info level log messages
Info(msg string, keysAndValues ...interface{})
// Error is used to log error level log messages
Error(err error, msg string, keysAndValues ...interface{})
// Debug is used to log debug level log messages
Debug(msg string, keysAndValues ...interface{})
}
## type [NoOpLogger](https://github.com/gojek/courier-go/blob/main/xds/log/logger.go#L14)

NoOpLogger is a noop implementation of Logger

type NoOpLogger struct{}
### func \(\*NoOpLogger\) [Debug](https://github.com/gojek/courier-go/blob/main/xds/log/logger.go#L23)
func (l *NoOpLogger) Debug(_ string, _ ...interface{})

Debug logs debug level log messages

### func \(\*NoOpLogger\) [Error](https://github.com/gojek/courier-go/blob/main/xds/log/logger.go#L20)
func (l *NoOpLogger) Error(_ error, _ string, _ ...interface{})

Error logs error level log messages

### func \(\*NoOpLogger\) [Info](https://github.com/gojek/courier-go/blob/main/xds/log/logger.go#L17)
func (l *NoOpLogger) Info(_ string, _ ...interface{})

Info logs info level log messages

Generated by gomarkdoc

- + \ No newline at end of file diff --git a/index.html b/index.html index 74c8997..677f8e7 100644 --- a/index.html +++ b/index.html @@ -4,13 +4,13 @@ Courier Go | Courier Go - +

Courier Go

Information Superhighway

MQTT Support

Courier Go supports MQTT v3.1.1

Middleware Chaining

Middlewares allow you to hook into lifecycle of courier client, helpful in adding loggers, tracers, metric collectors, etc.

OpenTelemetry Support

Supports TraceID propagation using OpenTelemetry protocol, can trace spans with a simple middleware addition.

Custom Codec Support

Custom codecs allow you to easily dictate serialisation/deserialisation of Golang structs.

xDS Support

xDS(envoy) support allows the courier client to do client side load balancing with Control Planes like Istio.

- + \ No newline at end of file