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
30 // "github.com/gmallard/stompngo"
35 nqs
= 1 // Default number of queues for multi-queue demo(s)
36 mdml
= 1024 * 32 // Message data max length of variable message, 32K
37 md
= make([]byte, 1) // Additional message data, primed during init()
38 rc
= 1 // Receiver connection count, srmgor_1smrconn
39 pbc
= 64 // Number of bytes to print (used in some
40 // // examples that receive).
42 sendFact
float64 = 1.0 // Send sleep time factor
43 recvFact
float64 = 1.0 // Receive sleep time factor
45 conn2Buffer
int = -1 // 2 connection buffer. < 0 means use queue size.
47 ackMode
= "auto" // The default ack mode
49 pprof
= false // Do not do profiling
54 p
:= "_123456789ABCDEF"
57 md
= bytes
.Repeat(b
, c
) // A long string
64 if s
:= os
.Getenv("STOMP_NQS"); s
!= "" {
65 i
, e
:= strconv
.ParseInt(s
, 10, 32)
67 log
.Println("NQS conversion error", e
)
75 // Receiver connection count
76 func Recvconns() (rc
int) {
78 if s
:= os
.Getenv("STOMP_RECVCONNS"); s
!= "" {
79 i
, e
:= strconv
.ParseInt(s
, 10, 32)
81 log
.Println("RECVCONNS conversion error", e
)
89 // Max Data Message Length
91 if s
:= os
.Getenv("STOMP_MDML"); s
!= "" {
92 i
, e
:= strconv
.ParseInt(s
, 10, 32)
94 log
.Println("MDML conversion error", e
)
97 p
:= "_123456789ABCDEF"
100 md
= bytes
.Repeat(b
, c
) // A long string
106 // Use profiling or not
108 if am
:= os
.Getenv("STOMP_PPROF"); am
!= "" {
114 // ACK mode for those examples that use it.
115 func AckMode() string {
116 if am
:= os
.Getenv("STOMP_ACKMODE"); am
!= "" {
117 if am
== "auto" || am
== "client" || am
== "client-individual" {
120 log
.Println("ACKMODE error", am
)
126 // 2 Connection Buffer Size
127 func Conn2Buffer() int {
128 if s
:= os
.Getenv("STOMP_CONN2BUFFER"); s
!= "" {
129 i
, e
:= strconv
.ParseInt(s
, 10, 32)
131 log
.Println("CONN2BUFFER conversion error", e
)
139 // Timestamp example ids
140 func ExampIdNow(s
string) string {
141 return time
.Now().String() + " " + s
144 // Get Send Sleep Factor
145 func SendFactor() float64 {
146 if s
:= os
.Getenv("STOMP_SENDFACT"); s
!= "" {
147 f
, e
:= strconv
.ParseFloat(s
, 64)
149 log
.Println("SENDFACT conversion error", e
)
151 sendFact
= float64(f
)
157 // Get Recv Sleep Factor
158 func RecvFactor() float64 {
159 if s
:= os
.Getenv("STOMP_RECVFACT"); s
!= "" {
160 f
, e
:= strconv
.ParseFloat(s
, 64)
162 log
.Println("RECVFACT conversion error", e
)
164 recvFact
= float64(f
)
170 // Get partial string, random length
171 func Partial() []byte {
172 r
:= int(ValueBetween(1, int64(mdml
-1), 1.0))
178 if s
:= os
.Getenv("STOMP_PBC"); s
!= "" {
179 i
, e
:= strconv
.ParseInt(s
, 10, 32)
181 log
.Println("PBC conversion error", e
)
189 // Does receive wait to simulate message processing
190 func RecvWait() bool {
191 f
:= os
.Getenv("STOMP_NORECVW")
198 // Does send wait to simulate message building
199 func SendWait() bool {
200 f
:= os
.Getenv("STOMP_NOSENDW")
207 // True if persistent messages are desired.
208 func Persistent() bool {
209 f
:= os
.Getenv("STOMP_PERSISTENT")
216 // True if max procs are to be set
217 func SetMAXPROCS() bool {
218 f
:= os
.Getenv("STOMP_SETMAXPROCS")