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 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. Note: this is a local TLS port.
26 # The broker does not require authentication.
27 STOMP_PORT=61611 go run conndisc_tls.go
37 // sngecomm methods are used specifically for these example clients.
38 "github.com/gmallard/stompngo_examples/sngecomm"
42 exampid
= "conndisc_tls: "
44 ll
= log
.New(os
.Stdout
, "TLCD ", log
.Ldate|log
.Lmicroseconds|log
.Lshortfile
)
48 // Connect to a STOMP broker using TLS and disconnect.
53 ll
.Printf("%stag:%s connsess:%s starts\n",
54 exampid
, tag
, sngecomm
.Lcs
)
56 // TLS Configuration. This configuration assumes that:
57 // a) The server used does *not* require client certificates
58 // b) This client has no need to authenticate the server
59 // Note that the tls.Config structure can be modified to support any
60 // authentication scheme, including two-way/mutual authentication. Examples
61 // are provided elsewhere in this project.
63 tc
.InsecureSkipVerify
= true // Do *not* check the server's certificate
65 // Standard example TLS connect sequence
66 n
, conn
, e
:= sngecomm
.CommonTLSConnect(exampid
, tag
, ll
, tc
)
68 ll
.Fatalf("%stag:%s connsess:%s main_on_connect error:%v",
69 exampid
, tag
, sngecomm
.Lcs
,
70 e
.Error()) // Handle this ......
74 sngecomm
.DumpTLSConfig(exampid
, tc
, nc
)
76 // *NOTE* application specific functionaltiy starts here!
78 // *NOTE* application specific functionaltiy ends here!
80 // Standard example disconnect sequence
81 e
= sngecomm
.CommonDisconnect(n
, conn
, exampid
, tag
, ll
)
83 ll
.Fatalf("%s %s\n", exampid
, e
.Error()) // Handle this ......
86 ll
.Printf("%stag:%s connsess:%s main_elapsed:%v\n",
87 exampid
, tag
, conn
.Session(),