MCPcopy Create free account
hub / github.com/assembla/cony / Example

Function Example

doc_test.go:12–82  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10)
11
12func Example() {
13 client := cony.NewClient(cony.URL(os.Getenv("AMQP_URL")), cony.Backoff(cony.DefaultBackoff))
14
15 q := &cony.Queue{
16 Name: "", // autogenerated queue name
17 AutoDelete: true,
18 }
19
20 exchange := cony.Exchange{
21 Name: "amq.topic",
22 Durable: true,
23 }
24
25 b := cony.Binding{
26 Queue: q,
27 Exchange: exchange,
28 Key: "something.#",
29 }
30
31 // wrap all declarations and save into slice
32 declarations := []cony.Declaration{
33 cony.DeclareQueue(q),
34 cony.DeclareExchange(exchange),
35 cony.DeclareBinding(b),
36 }
37
38 // declare consumer
39 consumer := cony.NewConsumer(q,
40 cony.Qos(10),
41 cony.AutoTag(),
42 cony.AutoAck(),
43 )
44
45 // declare publisher
46 publisher := cony.NewPublisher(exchange.Name,
47 "ololo.key",
48 cony.PublishingTemplate(amqp.Publishing{
49 ContentType: "application/json",
50 AppId: "app1",
51 }), // template amqp.Publising
52 )
53
54 // let client know about declarations
55 client.Declare(declarations)
56
57 // let client know about consumers/publishers
58 client.Consume(consumer)
59 client.Publish(publisher)
60
61 clientErrs := client.Errors()
62 deliveries := consumer.Deliveries()
63 consumerErrs := consumer.Errors()
64
65 // connect, reconnect, or exit loop
66 // run network operations such as:
67 // queue, exchange, bidning, consumers declarations
68 for client.Loop() {
69 select {

Callers

nothing calls this directly

Calls 11

DeclareMethod · 0.95
ConsumeMethod · 0.95
PublishMethod · 0.95
ErrorsMethod · 0.95
DeliveriesMethod · 0.95
ErrorsMethod · 0.95
LoopMethod · 0.95
WriteMethod · 0.95
CloseMethod · 0.95
BackoffMethod · 0.65
QosMethod · 0.65

Tested by

no test coverage detected