2 // Copyright © 2016-2018 Guy M. Allard
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 Package sngecomm provides common functionality used in the stompngo_examples
30 // "github.com/gmallard/stompngo"
35 nqs
= 1 // Default number of queues for multi-queue demo(s)
36 nqsLock sync
.Mutex
// nqs variable lock
37 mdml
= 1024 * 32 // Message data max length of variable message, 32K
38 md
= make([]byte, 1) // Additional message data, primed during init()
39 pbc
= 64 // Number of bytes to print (used in some examples that receive).
41 ngors
= 1 // Number of go routines to use (publish)
42 gorsleep
= "" // If non-empty, go routines will sleep (publish)
45 sendFact
= 1.0 // Send sleep time factor
46 recvFact
= 1.0 // Receive sleep time factor
48 ackMode
= "auto" // The default ack mode
50 pprof
= false // Do not do profiling
52 // TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 = 0xC0,0x2F
53 // TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 = 0xC0,0x2B
54 // TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 = 0xC0,0x30
55 cipherSuites
= []uint16{
61 useCustomCiphers
= false // Set Custom Cipher Suite list
63 memprof
= "" // memory profile file
64 cpuprof
= "" // cpu profile file
68 // EOFMsg is the EOF message body
74 p
:= "_123456789ABCDEF"
77 md
= bytes
.Repeat(b
, c
) // A long string
79 memprof
= os
.Getenv("STOMP_MEMPROF")
80 cpuprof
= os
.Getenv("STOMP_CPUPROF")
83 // Ngors sets the number of go routines
86 if s
:= os
.Getenv("STOMP_NGORS"); s
!= "" {
87 i
, e
:= strconv
.ParseInt(s
, 10, 32)
89 log
.Printf("v1:%v v2:%v\n", "NGORS conversion error", e
)
97 // Nqs sets the number of queues
101 defer nqsLock
.Unlock()
102 if s
:= os
.Getenv("STOMP_NQS"); s
!= "" {
103 i
, e
:= strconv
.ParseInt(s
, 10, 32)
105 log
.Printf("v1:%v v2:%v\n", "NQS conversion error", e
)
113 // Mdml sets the Max Data Message Length
115 if s
:= os
.Getenv("STOMP_MDML"); s
!= "" {
116 i
, e
:= strconv
.ParseInt(s
, 10, 32)
118 log
.Printf("v1:%v v2:%v\n", "MDML conversion error", e
)
121 p
:= "_123456789ABCDEF"
124 md
= bytes
.Repeat(b
, c
) // A long string
130 // Pprof indicates whether to use profiling or not
132 if am
:= os
.Getenv("STOMP_PPROF"); am
!= "" {
138 // Memprof returns the memory profile file name
139 func Memprof() string {
143 // Cpuprof returns the CPU profile file name
144 func Cpuprof() string {
148 // AckMode returns an ACK mode value for those examples that use it.
149 func AckMode() string {
150 if am
:= os
.Getenv("STOMP_ACKMODE"); am
!= "" {
151 if am
== "auto" || am
== "client" || am
== "client-individual" {
154 log
.Printf("v1:%v v2:%v\n", "ACKMODE error", am
)
160 // SendFactor returns the send sleep factor
161 func SendFactor() float64 {
162 if s
:= os
.Getenv("STOMP_SENDFACT"); s
!= "" {
163 f
, e
:= strconv
.ParseFloat(s
, 64)
165 log
.Printf("v1:%v v2:%v\n", "SENDFACT conversion error", e
)
167 sendFact
= float64(f
)
173 // RecvFactor returns the recv sleep factor
174 func RecvFactor() float64 {
175 if s
:= os
.Getenv("STOMP_RECVFACT"); s
!= "" {
176 f
, e
:= strconv
.ParseFloat(s
, 64)
178 log
.Printf("v1:%v v2:%v\n", "RECVFACT conversion error", e
)
180 recvFact
= float64(f
)
186 // Partial returns the partial byte slice for logging, random length
187 func Partial() []byte {
188 r
:= int(ValueBetween(1, int64(mdml
-1), 1.0))
192 // PartialSubstr returns the partial string for logging, fixed length
193 func PartialSubstr(l
int) []byte {
197 // Pbc returns the byte count to log
199 if s
:= os
.Getenv("STOMP_PBC"); s
!= "" {
200 i
, e
:= strconv
.ParseInt(s
, 10, 32)
202 log
.Printf("v1:%v v2:%v\n", "PBC conversion error", e
)
210 // Gorsleep returns an indication of whether go routines will sleep or not
211 func Gorsleep() string {
212 gorsleep
= os
.Getenv("STOMP_GORSLEEP")
216 // RecvWait indicates whether to wait in receives to simulate message processing
217 func RecvWait() bool {
218 f
:= os
.Getenv("STOMP_RECVWAIT")
225 // SendWait indicates whether to wait in sends to simulate message processing
226 func SendWait() bool {
227 f
:= os
.Getenv("STOMP_SENDWAIT")
234 // SetMAXPROCS returns true if max procs are to be set
235 func SetMAXPROCS() bool {
236 f
:= os
.Getenv("STOMP_SETMAXPROCS")
243 // UseCustomCiphers returns true if custom ciphers are to be used
244 func UseCustomCiphers() bool {
245 f
:= os
.Getenv("STOMP_USECUSTOMCIPHERS")
247 return useCustomCiphers
249 useCustomCiphers
= true
250 return useCustomCiphers
253 // CustomCiphers returns a slice of custom ciphers
254 func CustomCiphers() []uint16 {
255 if UseCustomCiphers() {
261 // Logger returns an indication of whether to do logging
262 func Logger() string {
263 return os
.Getenv("STOMP_LOGGER")
266 // UseEOF returns true if en EOF message is to be used.
268 if os
.Getenv("STOMP_USEEOF") != "" {