2 // Copyright © 2013-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 Connect and Disconnect from a STOMP broker using TCP.
22 # Connect to a broker with all defaults:
27 # Virtual Host is "localhost"
31 # Connect to a broker using STOMP protocol level 1.0:
32 STOMP_PROTOCOL=1.0 go run conndisc.go
34 # Connect to a broker using a custom host and port:
35 STOMP_HOST=tjjackson STOMP_PORT=62613 go run conndisc.go
37 # Connect to a broker using a custom port and virtual host:
38 STOMP_PORT=41613 STOMP_VHOST="/" go run conndisc.go
40 # Connect to a broker using a custom login and passcode:
41 STOMP_LOGIN="userid" STOMP_PASSCODE="t0ps3cr3t" go run conndisc.go
50 // sngecomm methods are used specifically for these example clients.
51 "github.com/gmallard/stompngo_examples/sngecomm"
55 exampid
= "conndisc: "
56 ll
= log
.New(os
.Stdout
, "ECNDS ", log
.Ldate|log
.Lmicroseconds|log
.Lshortfile
)
60 // Connect to a STOMP broker and disconnect.
65 // Standard example connect sequence
66 n
, conn
, e
:= sngecomm
.CommonConnect(exampid
, tag
, ll
)
69 ll
.Printf("%stag%s connsess:%s main_on_connect error Connect Response headers:%v body%s\n",
70 exampid
, tag
, conn
.Session(), conn
.ConnectResponse
.Headers
,
71 string(conn
.ConnectResponse
.Body
))
73 ll
.Fatalf("%stag:%s connsess:%s main_on_connect error:%v",
74 exampid
, tag
, sngecomm
.Lcs
,
75 e
.Error()) // Handle this ......
78 ll
.Printf("%stag%s connsess:%s Connect Response headers:%v body%s\n",
79 exampid
, tag
, conn
.Session(), conn
.ConnectResponse
.Headers
,
80 string(conn
.ConnectResponse
.Body
))
82 // *NOTE* application specific functionaltiy starts here!
84 // *NOTE* application specific functionaltiy ends here!
86 // Standard example disconnect sequence
87 e
= sngecomm
.CommonDisconnect(n
, conn
, exampid
, tag
, ll
)
89 ll
.Fatalf("%stag:%s connsess:%s main_on_disconnect error:%v",
90 exampid
, tag
, conn
.Session(),
91 e
.Error()) // Handle this ......
94 ll
.Printf("%stag:%s connsess:%s main_elapsed:%v\n",
95 exampid
, tag
, conn
.Session(),