This repository is a set of STOMP client examples using go.
These examples use the stomp client package here:
The reader is urged to become familiar with the go documentaion for the stompngo package:
stompngo documentation
stompngo wiki
A brief explanation of the individual examples follows. The list of consistes of example go, Java, and properties files:
Example Name | Explanation |
---|---|
ack/ack.go | Example of using ACK to acknowledge received messages. The STOMP destination should have been previously loaded with message(s). |
conndisc/conndisc.go | A very basic demonstration of a 'CONNECT' / 'DISCONNECT' sequence. |
conndisc_tls/conndisc_tls.go | A very basic demonstration of a 'CONNECT' / 'DISCONNECT' sequence with ssl (tls). You must connect to a broker port that is 'ssl/tls' enabled. |
jinterop |
A subdirectory which contains go and Java examples of a producer and consumer. This demonstrates interoperability between go and Java, and between STOMP and JMS. See individual files for details. Examples are provided for ActiveMQ and Artemis. Only the ActiveMQ artifacts are described here. It is assumed that the reader is familiar with Java, JMS, and JNDI. A number of helper shell scripts are provided. See the script descriptions below. These interoperability examples have some hard coded port numbers and path names. |
jinterop/activemq/Constants.java | Static constants used in the other Java programs in this directory. |
jinterop/activemq/jndi.properties | The JNDI properties file definition. |
jinterop/activemq/log4j.properties | The log4j properties file used by the Java code. |
jinterop/activemq/gorecv/gorecv.go | A message consumer written in go. |
jinterop/activemq/gosend/gosend.go | A message producer written in go. |
jinterop/activemq/Receiver.java | A message consumer written in Java using JMS. |
jinterop/activemq/Sender.java | A message producer written in Java using JMS. |
publish/publish.go | A classic 'putter'. Used to send an arbitrary number of messages to a given destination or destinations. |
receipts/onack/onack.go | Demonstrate obtaining a RECEIPT for an ACK request. |
receipts/onsend/onsend.go | Demonstrate obtaining a RECEIPT for a SEND request. |
recv_mds/recv_mds.go | An example intended to demonstrate how different brokers distribute output messages when a client subscribes multiple times to the same destination. |
sngecomm | A subdirectory which defines helper code for these examples. |
sngecomm/environment.go | Handle overrides from the environment for these examples. |
sngecomm/utilities.go | Utility routines used by these examples. |
srmgor_1conn/srmgor_1conn.go |
Send and receive, many go routines, one *stompngo.Connection. One sender go routine per destination. One receiver go routine per destination. |
srmgor_1smrconn/srmgor_1smrconn.go |
Send and receive, many go routines. One sender connection, with one go routine per destination. Many receiver connections: one receiver connection per destination (one go routine per connection). |
srmgor_2conn/srmgor_2conn.go |
Send and receive, two connections. Many go routines in the sender connection. Many go routines in the receiver connection. The receiver go routines illustrate a channel buffering technique that can be used with in bound message data. |
srmgor_manyconn/srmgor_manyconn.go |
Send and receive. Many sender connections. Many receiver connections. |
subscribe/subscribe.go | A basic demonstration of subscribing and receiving messages. |
tlsexamps |
A subdirectory demonstrating the use of TLS connections. All four primary TLS use cases are demonstrated. UseCase1) Client does not authenticate the broker and broker does not authenticate the client. UseCase2) Client does authenticate the broker but broker does not authenticate the client. UseCase3) Client does not authenticate the broker but broker does authenticate the client. UseCase4) Client does authenticate the broker and broker does authenticate the client. |
tlsexamps/tlsuc1/tlsuc1.go | UseCase1) Client does not authenticate the broker and broker does not authenticate the client. |
tlsexamps/tlsuc2/tlsuc2.go | UseCase2) Client does authenticate the broker but broker does not authenticate the client. |
tlsexamps/tlsuc3/tlsuc3.go | UseCase3) Client does not authenticate the broker but broker does authenticate the client. |
tlsexamps/tlsuc4/tlsuc4.go | UseCase4) Client does authenticate the broker and broker does authenticate the client. |
This is a list of script files used in the examples. There are very short scripts and it should be trivial to convert them to Windows .bat / .cmd files if necessary.
Script Name | Description |
---|---|
jinterop/activemq/clean.sh |
This is the clean up script for the Java / JMS interoperability examples. It removes all three .class files and the two go executables. |
jinterop/activemq/compile.sh |
This is the compile script for the Java / JMS interoperability examples. It compiles the Java and the go interoperability code. |
jinterop/activemq/cp.sh |
An internal script, sourced by some of the other scripts. It builds a list of jar files that will be included in the Java CLASSPATH. This script should be modified to support your environment. |
jinterop/activemq/gorecv.sh | This script runs the go receiver/consumer/getter. |
jinterop/activemq/gosend.sh | This script runs the go sender/producer/putter. |
jinterop/activemq/jrecv.sh | This script runs the Java receiver/consumer/getter. |
jinterop/activemq/jsend.sh | This script runs the Java sender/producer/putter. |
jinterop/activemq/runall.sh | This script runs all possible combinations of producers / consumers. |
srmgor_1conn/run.sh |
Send and receive, many go routines, one *stompngo.Connection. A logging helper script. |
srmgor_1smrconn/run.sh |
Send and receive, one sender connection with many go routines,
many receiver connections. A logging helper script. |
srmgor_2conn/run.sh |
Send and receive, one receiver connection with many go routines, one
sender connection with many go routines. A logging helper script. |
srmgor_manyconn/run.sh |
Send and receive, many receiver connections, many sender connections. A logging helper script. |
tlsexamps/tlsuc1/run.sh |
TLS Use Case 1. Example run script. |
tlsexamps/tlsuc2/runall.sh |
TLS Use Case 2. Example run script. Three separate runs, using different ports. |
tlsexamps/tlsuc2/run.sh |
TLS Use Case 2. Example run script. |
tlsexamps/tlsuc3/runall.sh |
TLS Use Case 3. Example run script. Three separate runs, using different ports. |
tlsexamps/tlsuc3/run.sh |
TLS Use Case 3. Example run script. |
tlsexamps/tlsuc4/runall.sh |
TLS Use Case 4. Example run script. Three separate runs, using different ports. |
tlsexamps/tlsuc4/run.sh |
TLS Use Case 4. Example run script. |
Note the author is accustomed to idiomatic go variable names (short if possible).
Variable Name | Common Use |
---|---|
ah | Ack headers. A stompngo.Headers instance. |
c | A loop couner. Because in some situations it makes sense. And because writing 'c++' for the end of loop action is amusing. |
ch | Connect headers. A stompngo.Headers instance, used for the initial CONNECT frame sent to the broker. |
conn |
A instance of a *stompngo.Connection, usually obtained from a call to
stompngo.Connect(...). Rename candidate: sc. |
d | A stomp destination, type string. Format and semantics are broker specific. |
dh | Disconnect headers. A stompngo.Headers instance. |
dt | A time.Duration instance. |
e | An instance of the go error type. |
h | A broker's (DNS) host name. |
hap |
A host and port name returned from net.JoinHostPort(h, p), type string. Example: localhost:61613. |
i | A loop counter. |
id | A (type 4) UUID obtained from calling stompngo.Uuid(), type string. |
irid | A receipt id, received from the broker, type string. |
ll | A go logger instance. |
mc | A message count. |
mcs | A message count, with type string. |
md | A stompngo.MessageData instance. The instance is retrieved from r (i.e. md := <-r) |
ms | A message body, with type string. |
mse | A message body, with addional data, type string. |
n | An implementation of the net.Conn interface, obtained by calling net.Dial. |
nmsgs |
The number of messages to process (produce/consume). Rename candidate: nm. |
nqs |
The number of destinations to use. Rename candidate: nd. |
nr | The number of receiver go routines. |
p | A broker's listener port. |
pbc |
The print byte count. When message bodies are printed, this is the
maximum number of bytes to print. Useful when message body sizes are
large. This is arbitrarily set to 64 unless overridden. If this is
set to 0, message bodies are (usually) not printed at all. Rename candidate: pc. TODO: consistently print no message body if this is <= 0. |
qc | A channel of type bool, used for signaling event completion. |
qn | A queue number identifier. Used in a looping control structure for a variable number of queues, or as a method parameter. |
qns | A queue number identifier, type string (from qn). |
r |
Used in the sngecomm subpackage only, for several reasons. TODO: this needs to change to a more meaningful variable name and documentation for same added. |
rd | A receipt message from the broker. An instance of type stompngo.MessageData. |
rf | A receive wait time multiplier. |
rid | A receipt id, type string. |
rw | A wait flag used by receivers. When set to true, receivers wait for a random amount of time after each message red. |
sbh | Subscribe headers. A stompngo.Headers instance. |
sc | A channel of type stompngo.MessageData. Used in example code to receive messages and metadata from the broker. |
sf | A send wait time multiplier. |
sh | Send headers. A stompngo.Headers instance. |
sw | A wait flag used by senders. When set to true, senders wait for a random amount of time after each send. |
si | A loop counter formatted as a string. |
tc | An instance of *tls.Config. |
tmr | A time.Timer. |
wga | Wait group for all sender and receiver go routines. |
wgr | Wait group for all receiver go routines. |
wgs | Wait group for all sender go routines. |
wh | Work headers. A stompngo.Headers instance. |
Variable Name | Common Use |
---|---|
b | A buffer, type []byte. |
c | An instance of *x509.Certificate. |
cc | An instance of tls.Certificate. |
cliCertFile | The full file name of the client's public cert in PEM format. |
cliKeyFile | The full file name of the client's private key in PEM format. |
e | An instance of error. |
k | An instance of *pem.Block. |
ll | A logger instance. |
nc | A pointer to a tls configuration, type *tls.Config, obtained from 'tls.Client'. |
svrCAFile | The full file name of the server CA's public cert in PEM format. |
t | An implementation of the net.Conn interface, obtained by calling net.Dial. |
tc | A pointer to a tls configuration, type *tls.Config, obtained from 'new'. |