Skip to content

Latest commit

 

History

History
290 lines (233 loc) · 7.17 KB

SENV.md

File metadata and controls

290 lines (233 loc) · 7.17 KB

senv - A stompngo helper (sub) package

The intent of this package is to assist the clients of the stompngo package when developing and using stompngo client application code.

This assistance is primarily implemented in the form of environment variables:

  • export=STOMP_var=value (Unix systems)
  • set STOMP_var=value (Windows systems)

Using these environment variables can help avoid or eliminate 'hard coding' values in the client code.

Environment variables and related subjects are discussed in the following sections:



Supported Environment Variables

The following table shows currently supported environment variables.

Environment Variable Name Usage
STOMP_DEST A destination to be used by the client.
Default: /queue/sng.sample.stomp.destination
STOMP_HEARTBEATS For protocol 1.1+, the heart-beat value to be used by the client in the CONNECT frame.
Default: 0,0
STOMP_HOST The broker host to connect to.
Default: localhost
STOMP_LOGIN The login to be used by the client in the CONNECT frame.
Default: guest
STOMP_NMSGS A default nummber of messages to receive or send. Useful for some clients.
Default: 1
STOMP_PASSCODE The passcode to be used by the client in the CONNECT frame.
Default: guest
STOMP_PERSISTENT May control use of the persistent header in SEND frames.
Default: no persistent header to be used.
Example:
STOMP_PERSISTENT=anyvalue
STOMP_PORT The broker port to connect to.
Default: 61613
STOMP_PROTOCOL For protocol 1.1+, the accept-version value to be used by the client in the CONNECT frame.
Default: 1.2
Multiple versions may be used per the STOMP specifications, e.g.:
STOMP_PROTOCOL="1.0,1.1,1.2"
STOMP_SUBCHANCAP Used to possibly override the default capacity of _stompngo_ subscription channels.
Default: 1 (the same as the _stompngo_ default.)
STOMP_VHOST For protocol 1.1+, the host value to be used by the client in the CONNECT frame.
Default: If not specified the default is STOMP_HOST (i.e. localhost).


Supported Helper Function

There is currently one helper function also provided by the senv package.

Function Name Usage
HostAndPort() This function returns two values, the STOMP_HOST and STOMP_PORT values.
Example:
h, p := senv.HostAndPort()


Example Code Fragments

Example code fragments follow.

STOMP_DEST Code Fragment

    sbh := ..... // Subscribe header, type stompngo.Headers
    if senv.Dest() != "" {
        sbh = sbh.Add("destination", senv.Dest())
    }

STOMP_HEARTBEATS Code Fragment

    ch := ..... // Connect headers, type stompngo.Headers
    if senv.Heartbeats() != "" {
        ch = ch.Add("heart-beat", senv.Heartbeats())
    }

STOMP_HOST Code Fragment

    ch := ..... // Connect headers, type stompngo.Headers
    if senv.Host() != "" {
        ch = ch.Add("host", senv.Host())
    }

STOMP_LOGIN Code Fragment

    ch := ..... // Connect headers, type stompngo.Headers
    if senv.Login() != "" {
        ch = ch.Add("login", senv.Login())
    }

STOMP_NMSGS Code Fragment

msg_count := senv.Nmsgs() // Default is 1

STOMP_PASSCODE Code Fragment

    ch := ..... // Connect headers, type stompngo.Headers
    if senv.Passcode() != "" {
        ch = ch.Add("passcode", senv.Passcode())
    }

STOMP_PERSISTENT Code Fragment

    sh := ..... // Send headers, type stompngo.Headers
    if senv.Persistent() != "" {
        ch = ch.Add("persistent", "true") // Brokers might need 'true' here
    }

STOMP_PORT Code Fragment

    ch := ..... // Connect headers, type stompngo.Headers
    if senv.Port() != "" {
        ch = ch.Add("port", senv.Port())
    }

STOMP_PROTOCOL Code Fragment

    ch := ..... // Connect headers, type stompngo.Headers
    if senv.Protocol() != "" {
        ch = ch.Add("accept-version", senv.Protocol())
    }

STOMP_VHOST Code Fragment

    ch := ..... // Connect headers, type stompngo.Headers
    if senv.Vhost() != "" {
        ch = ch.Add("host", senv.Vhost())
    }


Complete Connect Header Fragment

Obtaining a full set of headers to use for a stompngo.Connect might look like this:

    func ConnectHeaders() stompngo.Headers {
      h := stompngo.Headers{}
      l := senv.Login()
      if l != "" {
          h = h.Add("login", l)
      }
      pc := senv.Passcode()
      if pc != "" {
          h = h.Add("passcode", pc)
      }
      //
      p := senv.Protocol()
      if p != stompngo.SPL_10 { // 1.1 and 1.2
          h = h.Add("accept-version", p).Add("host", senv.Vhost())
      }
      //
      hb := senv.Heartbeats()
      if hb != "" {
          h = h.Add("heart-beat", hb)
      }
      return h
    }