MCPcopy Create free account
hub / github.com/streadway/amqp / ExampleDialTLS

Function ExampleDialTLS

examples_test.go:28–105  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26}
27
28func ExampleDialTLS() {
29 // This example assume you have a RabbitMQ node running on localhost
30 // with TLS enabled.
31 //
32 // The easiest way to create the CA, certificates and keys required for these
33 // examples is by using tls-gen: https://github.com/michaelklishin/tls-gen
34 //
35 // A comprehensive RabbitMQ TLS guide can be found at
36 // http://www.rabbitmq.com/ssl.html
37 //
38 // Once you have the required TLS files in place, use the following
39 // rabbitmq.config example for the RabbitMQ node that you will run on
40 // localhost:
41 //
42 // [
43 // {rabbit, [
44 // {tcp_listeners, []}, % listens on 127.0.0.1:5672
45 // {ssl_listeners, [5671]}, % listens on 0.0.0.0:5671
46 // {ssl_options, [{cacertfile,"/path/to/your/testca/cacert.pem"},
47 // {certfile,"/path/to/your/server/cert.pem"},
48 // {keyfile,"/path/to/your/server/key.pem"},
49 // {verify,verify_peer},
50 // {fail_if_no_peer_cert,true}]}
51 // ]}
52 // ].
53 //
54 //
55 // In the above rabbitmq.config example, we are disabling the plain AMQP port
56 // and verifying that clients and fail if no certificate is presented.
57 //
58 // The self-signing certificate authority's certificate (cacert.pem) must be
59 // included in the RootCAs to be trusted, otherwise the server certificate
60 // will fail certificate verification.
61 //
62 // Alternatively to adding it to the tls.Config. you can add the CA's cert to
63 // your system's root CAs. The tls package will use the system roots
64 // specific to each support OS. Under OS X, add (drag/drop) cacert.pem
65 // file to the 'Certificates' section of KeyChain.app to add and always
66 // trust. You can also add it via the command line:
67 //
68 // security add-certificate testca/cacert.pem
69 // security add-trusted-cert testca/cacert.pem
70 //
71 // If you depend on the system root CAs, then use nil for the RootCAs field
72 // so the system roots will be loaded instead.
73 //
74 // Server names are validated by the crypto/tls package, so the server
75 // certificate must be made for the hostname in the URL. Find the commonName
76 // (CN) and make sure the hostname in the URL matches this common name. Per
77 // the RabbitMQ instructions (or tls-gen) for a self-signed cert, this defaults to the
78 // current hostname.
79 //
80 // openssl x509 -noout -in /path/to/certificate.pem -subject
81 //
82 // If your server name in your certificate is different than the host you are
83 // connecting to, set the hostname used for verification in
84 // ServerName field of the tls.Config struct.
85 cfg := new(tls.Config)

Callers

nothing calls this directly

Calls 1

DialTLSFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…