2 // Copyright © 2013-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 Connect and Disconnect from a STOMP broker using TLS.
20 All examples in the 'conndisc' directory also apply here. This example shows
21 that TLS is requested by using a specific port and tls.Dial.
25 # Connect to a broker using TLS:
26 STOMP_PORT=61612 go run conndisc_tls.go
36 // sngecomm methods are used specifically for these example clients.
37 "github.com/gmallard/stompngo_examples/sngecomm"
41 exampid
= "conndisc_tls: "
43 ll
= log
.New(os
.Stdout
, "TLCD ", log
.Ldate|log
.Lmicroseconds|log
.Lshortfile
)
47 // Connect to a STOMP broker using TLS and disconnect.
52 ll
.Printf("%stag:%s connsess:%s starts\n",
53 exampid
, tag
, sngecomm
.Lcs
)
55 // TLS Configuration. This configuration assumes that:
56 // a) The server used does *not* require client certificates
57 // b) This client has no need to authenticate the server
58 // Note that the tls.Config structure can be modified to support any
59 // authentication scheme, including two-way/mutual authentication. Examples
60 // are provided elsewhere in this project.
62 tc
.InsecureSkipVerify
= true // Do *not* check the server's certificate
64 // Standard example TLS connect sequence
65 n
, conn
, e
:= sngecomm
.CommonTLSConnect(exampid
, tag
, ll
, tc
)
67 ll
.Fatalf("%stag:%s connsess:%s main_on_connect error:%v",
68 exampid
, tag
, sngecomm
.Lcs
,
69 e
.Error()) // Handle this ......
73 sngecomm
.DumpTLSConfig(exampid
, tc
, nc
)
75 // *NOTE* application specific functionaltiy starts here!
77 // *NOTE* application specific functionaltiy ends here!
79 // Standard example disconnect sequence
80 e
= sngecomm
.CommonDisconnect(n
, conn
, exampid
, tag
, ll
)
82 ll
.Fatalf("%s %s\n", exampid
, e
.Error()) // Handle this ......
85 ll
.Printf("%stag:%s connsess:%s main_elapsed:%v\n",
86 exampid
, tag
, conn
.Session(),