2 // Copyright © 2016 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
29 // "github.com/gmallard/stompngo"
34 nqs
= 1 // Default number of queues for multi-queue demo(s)
35 mdml
= 1024 * 32 // Message data max length of variable message, 32K
36 md
= make([]byte, 1) // Additional message data, primed during init()
37 pbc
= 64 // Number of bytes to print (used in some examples that receive).
39 ngors
= 1 // Number of go routines to use (publish)
40 gorsleep
= "" // If non-empty, go routines will sleep (publish)
43 sendFact
float64 = 1.0 // Send sleep time factor
44 recvFact
float64 = 1.0 // Receive sleep time factor
46 ackMode
= "auto" // The default ack mode
48 pprof
= false // Do not do profiling
50 // TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 = 0xC0,0x2F
51 // TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 = 0xC0,0x2B
52 // TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 = 0xC0,0x30
53 cipherSuites
= []uint16{
59 useCustomCiphers
= false // Set Custom Cipher Suite list
61 memprof
= "" // memory profile file
62 cpuprof
= "" // cpu profile file
71 p
:= "_123456789ABCDEF"
74 md
= bytes
.Repeat(b
, c
) // A long string
76 memprof
= os
.Getenv("STOMP_MEMPROF")
77 cpuprof
= os
.Getenv("STOMP_CPUPROF")
80 // Number of go routines
83 if s
:= os
.Getenv("STOMP_NGORS"); s
!= "" {
84 i
, e
:= strconv
.ParseInt(s
, 10, 32)
86 log
.Printf("v1:%v v2:%v\n", "NGORS conversion error", e
)
97 if s
:= os
.Getenv("STOMP_NQS"); s
!= "" {
98 i
, e
:= strconv
.ParseInt(s
, 10, 32)
100 log
.Printf("v1:%v v2:%v\n", "NQS conversion error", e
)
108 // Max Data Message Length
110 if s
:= os
.Getenv("STOMP_MDML"); s
!= "" {
111 i
, e
:= strconv
.ParseInt(s
, 10, 32)
113 log
.Printf("v1:%v v2:%v\n", "MDML conversion error", e
)
116 p
:= "_123456789ABCDEF"
119 md
= bytes
.Repeat(b
, c
) // A long string
125 // Use profiling or not
127 if am
:= os
.Getenv("STOMP_PPROF"); am
!= "" {
133 // Memory profile file
134 func Memprof() string {
139 func Cpuprof() string {
143 // ACK mode for those examples that use it.
144 func AckMode() string {
145 if am
:= os
.Getenv("STOMP_ACKMODE"); am
!= "" {
146 if am
== "auto" || am
== "client" || am
== "client-individual" {
149 log
.Printf("v1:%v v2:%v\n", "ACKMODE error", am
)
155 // Get Send Sleep Factor
156 func SendFactor() float64 {
157 if s
:= os
.Getenv("STOMP_SENDFACT"); s
!= "" {
158 f
, e
:= strconv
.ParseFloat(s
, 64)
160 log
.Printf("v1:%v v2:%v\n", "SENDFACT conversion error", e
)
162 sendFact
= float64(f
)
168 // Get Recv Sleep Factor
169 func RecvFactor() float64 {
170 if s
:= os
.Getenv("STOMP_RECVFACT"); s
!= "" {
171 f
, e
:= strconv
.ParseFloat(s
, 64)
173 log
.Printf("v1:%v v2:%v\n", "RECVFACT conversion error", e
)
175 recvFact
= float64(f
)
181 // Get partial string, random length
182 func Partial() []byte {
183 r
:= int(ValueBetween(1, int64(mdml
-1), 1.0))
187 // Get partial string, fixed length
188 func PartialSubstr(l
int) []byte {
194 if s
:= os
.Getenv("STOMP_PBC"); s
!= "" {
195 i
, e
:= strconv
.ParseInt(s
, 10, 32)
197 log
.Printf("v1:%v v2:%v\n", "PBC conversion error", e
)
205 // Whether go routines will sleep or not
206 func Gorsleep() string {
207 gorsleep
= os
.Getenv("STOMP_GORSLEEP")
211 // Does receive wait to simulate message processing
212 func RecvWait() bool {
213 f
:= os
.Getenv("STOMP_RECVWAIT")
220 // Does send wait to simulate message building
221 func SendWait() bool {
222 f
:= os
.Getenv("STOMP_SENDWAIT")
229 // True if max procs are to be set
230 func SetMAXPROCS() bool {
231 f
:= os
.Getenv("STOMP_SETMAXPROCS")
238 // Use Custon Cipher List
239 func UseCustomCiphers() bool {
240 f
:= os
.Getenv("STOMP_USECUSTOMCIPHERS")
242 return useCustomCiphers
244 useCustomCiphers
= true
245 return useCustomCiphers
249 func CustomCiphers() []uint16 {
250 if UseCustomCiphers() {
257 func Logger() string {
258 return os
.Getenv("STOMP_LOGGER")
261 // Use special EOF message
263 if os
.Getenv("STOMP_USEEOF") != "" {