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
38 // // examples that receive).
40 sendFact
float64 = 1.0 // Send sleep time factor
41 recvFact
float64 = 1.0 // Receive sleep time factor
43 ackMode
= "auto" // The default ack mode
45 pprof
= false // Do not do profiling
50 p
:= "_123456789ABCDEF"
53 md
= bytes
.Repeat(b
, c
) // A long string
60 if s
:= os
.Getenv("STOMP_NQS"); s
!= "" {
61 i
, e
:= strconv
.ParseInt(s
, 10, 32)
63 log
.Printf("v1:%v v2:%v\n", "NQS conversion error", e
)
71 // Max Data Message Length
73 if s
:= os
.Getenv("STOMP_MDML"); s
!= "" {
74 i
, e
:= strconv
.ParseInt(s
, 10, 32)
76 log
.Printf("v1:%v v2:%v\n", "MDML conversion error", e
)
79 p
:= "_123456789ABCDEF"
82 md
= bytes
.Repeat(b
, c
) // A long string
88 // Use profiling or not
90 if am
:= os
.Getenv("STOMP_PPROF"); am
!= "" {
96 // ACK mode for those examples that use it.
97 func AckMode() string {
98 if am
:= os
.Getenv("STOMP_ACKMODE"); am
!= "" {
99 if am
== "auto" || am
== "client" || am
== "client-individual" {
102 log
.Printf("v1:%v v2:%v\n", "ACKMODE error", am
)
108 // Get Send Sleep Factor
109 func SendFactor() float64 {
110 if s
:= os
.Getenv("STOMP_SENDFACT"); s
!= "" {
111 f
, e
:= strconv
.ParseFloat(s
, 64)
113 log
.Printf("v1:%v v2:%v\n", "SENDFACT conversion error", e
)
115 sendFact
= float64(f
)
121 // Get Recv Sleep Factor
122 func RecvFactor() float64 {
123 if s
:= os
.Getenv("STOMP_RECVFACT"); s
!= "" {
124 f
, e
:= strconv
.ParseFloat(s
, 64)
126 log
.Printf("v1:%v v2:%v\n", "RECVFACT conversion error", e
)
128 recvFact
= float64(f
)
134 // Get partial string, random length
135 func Partial() []byte {
136 r
:= int(ValueBetween(1, int64(mdml
-1), 1.0))
142 if s
:= os
.Getenv("STOMP_PBC"); s
!= "" {
143 i
, e
:= strconv
.ParseInt(s
, 10, 32)
145 log
.Printf("v1:%v v2:%v\n", "PBC conversion error", e
)
153 // Does receive wait to simulate message processing
154 func RecvWait() bool {
155 f
:= os
.Getenv("STOMP_NORECVW")
162 // Does send wait to simulate message building
163 func SendWait() bool {
164 f
:= os
.Getenv("STOMP_NOSENDW")
171 // True if max procs are to be set
172 func SetMAXPROCS() bool {
173 f
:= os
.Getenv("STOMP_SETMAXPROCS")