1 # senv - A stompngo helper (sub) package
3 The intent of this package is to assist the clients of the
4 _stompngo_ package when developing and using _stompngo_ client application
7 This assistance is _primarily_ implemented in the form of environment variables:
9 * export=STOMP_var=value (Unix systems)
10 * set STOMP_var=value (Windows systems)
12 Using these environment variables can help avoid or eliminate 'hard coding'
13 values in the client code.
15 Environment variables and related subjects are discussed in the following sections:
17 * [Supported Environment Variables](#senv)
18 * [Supported Helper Function](#shf)
19 * [Example Code Fragments](#ecf)
20 * [Complete Connect Header Fragment](#cchf)
25 ## <a name="sev"></a>Supported Environment Variables
27 The following table shows currently supported environment variables.
29 <table border="1" style="width:80%;border: 1px solid black;">
31 <th style="width:20%;border: 1px solid black;padding-left: 10px;" >
32 Environment Variable Name
34 <th style="width:60%border: 1px solid black;padding-left: 10px;" >
40 <td style="border: 1px solid black;padding-left: 10px;" >
43 <td style="border: 1px solid black;padding-left: 10px;" >
44 A destination to be used by the client.<br />
45 Default: /queue/sng.sample.stomp.destination
50 <td style="border: 1px solid black;padding-left: 10px;" >
53 <td style="border: 1px solid black;padding-left: 10px;" >
54 For protocol 1.1+, the heart-beat value to be used by the client in the CONNECT frame.<br />
60 <td style="border: 1px solid black;padding-left: 10px;" >
63 <td style="border: 1px solid black;padding-left: 10px;" >
64 The broker host to connect to.<br />
70 <td style="border: 1px solid black;padding-left: 10px;" >
73 <td style="border: 1px solid black;padding-left: 10px;" >
74 The login to be used by the client in the CONNECT frame.<br />
80 <td style="border: 1px solid black;padding-left: 10px;" >
83 <td style="border: 1px solid black;padding-left: 10px;" >
84 A default nummber of messages to receive or send. Useful for some clients.<br />
90 <td style="border: 1px solid black;padding-left: 10px;" >
93 <td style="border: 1px solid black;padding-left: 10px;" >
94 The passcode to be used by the client in the CONNECT frame.<br />
100 <td style="border: 1px solid black;padding-left: 10px;" >
103 <td style="border: 1px solid black;padding-left: 10px;" >
104 May control use of the persistent header in SEND frames.<br />
105 Default: no persistent header to be used.<br />
107 STOMP_PERSISTENT=anyvalue
112 <td style="border: 1px solid black;padding-left: 10px;" >
115 <td style="border: 1px solid black;padding-left: 10px;" >
116 The broker port to connect to.<br />
122 <td style="border: 1px solid black;padding-left: 10px;" >
125 <td style="border: 1px solid black;padding-left: 10px;" >
126 For protocol 1.1+, the accept-version value to be used by the client in the CONNECT frame.<br />
128 Multiple versions may be used per the STOMP specifications, e.g.:<br />
129 STOMP_PROTOCOL="1.0,1.1,1.2"
134 <td style="border: 1px solid black;padding-left: 10px;" >
137 <td style="border: 1px solid black;padding-left: 10px;" >
138 Used to possibly override the default capacity of _stompngo_ subscription channels.<br />
139 Default: 1 (the same as the _stompngo_ default.)
144 <td style="border: 1px solid black;padding-left: 10px;" >
147 <td style="border: 1px solid black;padding-left: 10px;" >
148 For protocol 1.1+, the host value to be used by the client in the CONNECT frame.<br />
149 Default: If not specified the default is STOMP_HOST (i.e. localhost).
158 ## <a name="shf"></a>Supported Helper Function
160 There is currently one helper function also provided by the _senv_ package.
162 <table border="1" style="width:80%;border: 1px solid black;">
164 <th style="width:20%;border: 1px solid black;padding-left: 10px;" >
167 <th style="width:60%border: 1px solid black;padding-left: 10px;" >
173 <td style="border: 1px solid black;padding-left: 10px;" >
176 <td style="border: 1px solid black;padding-left: 10px;" >
177 This function returns two values, the STOMP_HOST and STOMP_PORT values.<br />
179 h, p := senv.HostAndPort()
189 ## <a name="ecf"></a>Example Code Fragments
191 Example code fragments follow.
193 ### STOMP_DEST Code Fragment
195 sbh := ..... // Subscribe header, type stompngo.Headers
196 if senv.Dest() != "" {
197 sbh = sbh.Add("destination", senv.Dest())
200 ### STOMP_HEARTBEATS Code Fragment
202 ch := ..... // Connect headers, type stompngo.Headers
203 if senv.Heartbeats() != "" {
204 ch = ch.Add("heart-beat", senv.Heartbeats())
207 ### STOMP_HOST Code Fragment
209 ch := ..... // Connect headers, type stompngo.Headers
210 if senv.Host() != "" {
211 ch = ch.Add("host", senv.Host())
214 ### STOMP_LOGIN Code Fragment
216 ch := ..... // Connect headers, type stompngo.Headers
217 if senv.Login() != "" {
218 ch = ch.Add("login", senv.Login())
221 ### STOMP_NMSGS Code Fragment
223 msg_count := senv.Nmsgs() // Default is 1
225 ### STOMP_PASSCODE Code Fragment
227 ch := ..... // Connect headers, type stompngo.Headers
228 if senv.Passcode() != "" {
229 ch = ch.Add("passcode", senv.Passcode())
232 ### STOMP_PERSISTENT Code Fragment
234 sh := ..... // Send headers, type stompngo.Headers
235 if senv.Persistent() != "" {
236 ch = ch.Add("persistent", "true") // Brokers might need 'true' here
239 ### STOMP_PORT Code Fragment
241 ch := ..... // Connect headers, type stompngo.Headers
242 if senv.Port() != "" {
243 ch = ch.Add("port", senv.Port())
246 ### STOMP_PROTOCOL Code Fragment
248 ch := ..... // Connect headers, type stompngo.Headers
249 if senv.Protocol() != "" {
250 ch = ch.Add("accept-version", senv.Protocol())
253 ### STOMP_VHOST Code Fragment
255 ch := ..... // Connect headers, type stompngo.Headers
256 if senv.Vhost() != "" {
257 ch = ch.Add("host", senv.Vhost())
263 ## <a name="cchf"></a>Complete Connect Header Fragment
265 Obtaining a full set of headers to use for a _stompngo.Connect_ might
268 func ConnectHeaders() stompngo.Headers {
269 h := stompngo.Headers{}
272 h = h.Add("login", l)
274 pc := senv.Passcode()
276 h = h.Add("passcode", pc)
280 if p != stompngo.SPL_10 { // 1.1 and 1.2
281 h = h.Add("accept-version", p).Add("host", senv.Vhost())
284 hb := senv.Heartbeats()
286 h = h.Add("heart-beat", hb)