Add putget to make logic.
[stompngo_examples.git] / conndisc / conndisc.go
blob2172001051d08990a8b5d074c68f139984c2fe7f
1 //
2 // Copyright © 2013-2018 Guy M. Allard
3 //
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
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
20 Examples:
22 # Connect to a broker with all defaults:
23 # Host is "localhost"
24 # Port is 61613
25 # Login is "guest"
26 # Passcode is "guest
27 # Virtual Host is "localhost"
28 # Protocol is 1.1
29 go run conndisc.go
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
44 package main
46 import (
47 "log"
48 "os"
49 "time"
50 // sngecomm methods are used specifically for these example clients.
51 "github.com/gmallard/stompngo_examples/sngecomm"
54 var (
55 exampid = "conndisc: "
56 ll = log.New(os.Stdout, "ECNDS ", log.Ldate|log.Lmicroseconds|log.Lshortfile)
57 tag = "condiscmain"
60 // Connect to a STOMP broker and disconnect.
61 func main() {
63 st := time.Now()
65 // Standard example connect sequence
66 n, conn, e := sngecomm.CommonConnect(exampid, tag, ll)
67 if e != nil {
68 ll.Printf("%stag%s main_on_connect error basic:\nerror:%v\nconn:%v\n",
69 exampid, tag, e.Error(), conn)
70 if conn != nil && conn.ConnectResponse != nil {
71 ll.Printf("%stag%s connsess:%s main_on_connect error Connect Response headers:%v body%s\n",
72 exampid, tag, conn.Session(), conn.ConnectResponse.Headers,
73 string(conn.ConnectResponse.Body))
75 ll.Fatalf("%stag:%s connsess:%s main_on_connect FATAL error:%v",
76 exampid, tag, sngecomm.Lcs,
77 e.Error()) // Handle this ......
80 ll.Printf("%stag%s connsess:%s Connect Response headers:%v body%s\n",
81 exampid, tag, conn.Session(), conn.ConnectResponse.Headers,
82 string(conn.ConnectResponse.Body))
84 // *NOTE* application specific functionaltiy starts here!
85 // For you to add.
86 // *NOTE* application specific functionaltiy ends here!
88 // Standard example disconnect sequence
89 e = sngecomm.CommonDisconnect(n, conn, exampid, tag, ll)
90 if e != nil {
91 ll.Fatalf("%stag:%s connsess:%s main_on_disconnect error:%v",
92 exampid, tag, conn.Session(),
93 e.Error()) // Handle this ......
96 ll.Printf("%stag:%s connsess:%s main_elapsed:%v\n",
97 exampid, tag, conn.Session(),
98 time.Now().Sub(st))