JMS interop examples updated for common code / logging.
[stompngo_examples.git] / conndisc / conndisc.go
blob86584fd7c2a7b5d96b429902da5382955ece46f4
1 //
2 // Copyright © 2013-2016 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.Fatalf("%stag:%s connsess:%s main_on_connect error:%v",
69 exampid, tag, sngecomm.Lcs,
70 e.Error()) // Handle this ......
73 // *NOTE* application specific functionaltiy starts here!
74 // For you to add.
75 // *NOTE* application specific functionaltiy ends here!
77 // Standard example disconnect sequence
78 e = sngecomm.CommonDisconnect(n, conn, exampid, tag, ll)
79 if e != nil {
80 ll.Fatalf("%stag:%s connsess:%s main_on_disconnect error:%v",
81 exampid, tag, conn.Session(),
82 e.Error()) // Handle this ......
85 ll.Printf("%stag:%s connsess:%s main_elapsed:%v\n",
86 exampid, tag, conn.Session(),
87 time.Now().Sub(st))