Skip to content

Commit 962fd41

Browse files
author
Sean Treadway
committed
Documentation cleanup
Start each documentation block with the method or type name and move the first paragraph into the active voice.
1 parent 5cbca36 commit 962fd41

File tree

7 files changed

+207
-154
lines changed

7 files changed

+207
-154
lines changed

auth.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import (
99
"fmt"
1010
)
1111

12-
// Interface to encode different SASL authentication mechanisms used during connection tuning.
12+
// Authentication interface provides a means for different SASL authentication
13+
// mechanisms to be used during connection tuning.
1314
type Authentication interface {
1415
Mechanism() string
1516
Response() string
1617
}
1718

19+
// PlainAuth is a similar to Basic Auth in HTTP.
1820
type PlainAuth struct {
1921
Username string
2022
Password string

channel.go

+139-118
Large diffs are not rendered by default.

connection.go

+33-13
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import (
1717
"time"
1818
)
1919

20-
// Used in Open to specify the desired tuning parameters used during a
21-
// connection open handshake. The negotiated tuning will be stored in the
22-
// resultant connection.
20+
// Config is used in Open to specify the desired tuning parameters used during
21+
// a connection open handshake. The negotiated tuning will be stored in the
22+
// returned connection's Config field.
2323
type Config struct {
2424
// The SASL mechanisms to try in the client request, and the successful
2525
// mechanism used on the Connection object
@@ -32,8 +32,11 @@ type Config struct {
3232
Heartbeat time.Duration // less than 1s interval means no heartbeats
3333
}
3434

35-
// Manages the serialization and deserialization of frames from IO and
36-
// dispatches the frames to the appropriate channel.
35+
// Connection manages the serialization and deserialization of frames from IO
36+
// and dispatches the frames to the appropriate channel. All RPC methods and
37+
// asyncronous Publishing, Delivery, Ack, Nack and Return messages are
38+
// multiplexed on this channel. There must always be active receivers for
39+
// every asynchronous message on this connection.
3740
type Connection struct {
3841
destructor sync.Once
3942
m sync.Mutex // writer and notify mutex
@@ -91,6 +94,12 @@ func Dial(amqp string) (*Connection, error) {
9194
})
9295
}
9396

97+
/*
98+
Open accepts an already established connection, or other io.ReadWriteCloser as
99+
a transport. Use this method if you have established a TLS connection or wish
100+
to use your own custom transport.
101+
102+
*/
94103
func Open(conn io.ReadWriteCloser, config Config) (*Connection, error) {
95104
me := &Connection{
96105
conn: conn,
@@ -108,10 +117,16 @@ func (me *Connection) nextChannelId() uint16 {
108117
return uint16(atomic.AddUint32(&me.sequence, 1))
109118
}
110119

111-
// Listens for close events either initiated by an error accompaning a
112-
// connection.close method or by a normal shutdown.
113-
//
114-
// On normal shutdowns, the chan will be closed.
120+
/*
121+
NotifyClose registers a listener for close events either initiated by an error
122+
accompaning a connection.close method or by a normal shutdown.
123+
124+
On normal shutdowns, the chan will be closed.
125+
126+
To reconnect after a transport or protocol error, register a listener here and
127+
re-run your setup process.
128+
129+
*/
115130
func (me *Connection) NotifyClose(c chan *Error) chan *Error {
116131
me.m.Lock()
117132
defer me.m.Unlock()
@@ -120,10 +135,10 @@ func (me *Connection) NotifyClose(c chan *Error) chan *Error {
120135
}
121136

122137
/*
123-
Requests, and waits for the response to close the AMQP connection.
138+
Close requests and waits for the response to close the AMQP connection.
124139
125-
It's advisable to use this message when publishing so to make sure that all
126-
kernel buffers have been flushed before exiting.
140+
It's advisable to use this message when publishing to ensure all kernel buffers
141+
have been flushed on the server and client before exiting.
127142
128143
An error indicates that server may not have received this request to close but
129144
the connection should be treated as closed regardless.
@@ -349,7 +364,12 @@ func (me *Connection) isCapable(featureName string) bool {
349364
return false
350365
}
351366

352-
// Constructs and opens a unique channel for concurrent operations
367+
/*
368+
Channel opens a unique, concurrent server channel to process the bulk of AMQP
369+
messages. Any error from methods on this receiver will render the receiver
370+
invalid and a new Channel should be opened.
371+
372+
*/
353373
func (me *Connection) Channel() (*Channel, error) {
354374
id := me.nextChannelId()
355375
channel := newChannel(me, id)

delivery.go

+11-7
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import (
99
"time"
1010
)
1111

12-
// A delivery from the server to a consumer started with Queue.Consume or
13-
// Queue.Get.
12+
// Delivery captures the fields for a previously delivered message resident in
13+
// a queue to be delivered by the server to a consumer from Channel.Consume or
14+
// Channel.Get.
1415
type Delivery struct {
1516
channel *Channel
1617

@@ -88,6 +89,8 @@ func newDelivery(channel *Channel, msg messageWithContent) *Delivery {
8889
}
8990

9091
/*
92+
Ack acknowledges that the client or server has finished work on a delivery.
93+
9194
All deliveries in AMQP must be acknowledged. If you called Channel.Consume
9295
with autoAck true then the server will be automatically ack each message and
9396
this method should not be called. Otherwise, you must call Delivery.Ack after
@@ -111,7 +114,7 @@ func (me Delivery) Ack(multiple bool) error {
111114
}
112115

113116
/*
114-
Negatively acknowledge processing of this message.
117+
Reject negatively acknowledge processing of this message.
115118
116119
When requeue is true, queue this message to be delivered to a consumer on a
117120
different channel. When requeue is false or the server is unable to queue this
@@ -131,17 +134,18 @@ func (me Delivery) Reject(requeue bool) error {
131134
}
132135

133136
/*
134-
Uses the consumer identity in this delivery to cancel the consumer delegating
135-
to Channel.Cancel. An error indicates the channel is closed.
137+
Cancel delegates to a Channel.Cancel and uses the consumer identity in this delivery to cancel the consumer.
138+
139+
An error indicates the channel is closed.
136140
137141
*/
138142
func (me Delivery) Cancel(noWait bool) error {
139143
return me.channel.Cancel(me.ConsumerTag, noWait)
140144
}
141145

142146
/*
143-
RabbitMQ extension - Negatively acknowledge the delivery of message(s)
144-
identified by the deliveryTag.
147+
Nack negatively acknowledge the delivery of message(s) identified by the
148+
deliveryTag from either from either the client or server.
145149
146150
When multiple is true, nack messages up to and including delivered messages up
147151
until the deliveryTag delivered on the same channel.

doc.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
/*
77
AMQP 0.9.1 client with RabbitMQ extensions
88
9-
Start out with understanding the AMQP 0.9.1 messaging model by reviewing these
10-
links. Much of the terminology in this library directly relates to AMQP
11-
concepts.
9+
Understand the AMQP 0.9.1 messaging model by reviewing these links first. Much
10+
of the terminology in this library directly relates to AMQP concepts.
1211
1312
Resources
1413
@@ -58,6 +57,10 @@ The Notify* methods with Connection and Channel receivers model the pattern of
5857
asynchronous events like closes due to exceptions, or messages that are sent out
5958
of band from an RPC call like basic.ack or basic.flow.
6059
60+
Any asynchronous events, including Deliveries and Publishings must always have
61+
a receiver until the corresponding chans are closed. Without asynchronous
62+
receivers, the sychronous methods will block.
63+
6164
Typical Use Case
6265
6366
It's important as a client to an AMQP topology to ensure the state of the

return.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"time"
1010
)
1111

12-
// A flattened struct of fields returned by the server when a Publishing is
13-
// unable to be delivered either due to the `mandatory` flag set and no route
14-
// found, or `immediate` flag set and no free consumer.
12+
// Return captures a flattened struct of fields returned by the server when a
13+
// Publishing is unable to be delivered either due to the `mandatory` flag set
14+
// and no route found, or `immediate` flag set and no free consumer.
1515
type Return struct {
1616
ReplyCode uint16 // reason
1717
ReplyText string // description

types.go

+12-9
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ var (
2323
ErrUnexpectedFrame = &Error{Code: UnexpectedFrame, Reason: "unexpected frame received"}
2424
)
2525

26-
// The code and reason a channel or connection has been closed by the server.
26+
// Error captures the code and reason a channel or connection has been closed
27+
// by the server.
2728
type Error struct {
2829
Code int // constant code from the specification
2930
Reason string // description of the error
@@ -96,17 +97,18 @@ const (
9697
flagReserved1 = 0x0004
9798
)
9899

99-
// Current state of the queue on the server returned from Channel.QueueDeclare or
100-
// Channel.QueueInspect.
100+
// Queue captures the current server state of the queue on the server returned
101+
// from Channel.QueueDeclare or Channel.QueueInspect.
101102
type Queue struct {
102103
Name string // server confirmed or generated name
103104
Messages int // count of messages not awaiting acknowledgment
104105
Consumers int // number of consumers receiving deliveries
105106
}
106107

107-
// A published message from the client to the server. The fields outside of
108-
// the Headers table included in this struct mirror the underlying fields in
109-
// the content frame. They use native types for convienence and efficiency.
108+
// Publishing captures the client message sent to the server. The fields
109+
// outside of the Headers table included in this struct mirror the underlying
110+
// fields in the content frame. They use native types for convienence and
111+
// efficiency.
110112
type Publishing struct {
111113
// Application or exchange specific fields,
112114
// the headers exchange will inspect this field.
@@ -126,17 +128,18 @@ type Publishing struct {
126128
UserId string // creating user id - ex: "guest"
127129
AppId string // creating application id
128130

131+
// The application specific payload of the message
129132
Body []byte
130133
}
131134

132-
// The golang type that matches the amqp type. Scale is the number of decimal digits
133-
// Scale == 2, Value == 12345, Decimal == 123.45
135+
// Decimal matches the AMQP decimal type. Scale is the number of decimal
136+
// digits Scale == 2, Value == 12345, Decimal == 123.45
134137
type Decimal struct {
135138
Scale uint8
136139
Value int32
137140
}
138141

139-
// The amqp type that represents a string to field. Most Go types are supported in
142+
// Table matches the amqp table type for string to field mappings. Most Go types are supported in
140143
// table serialization.
141144
type Table map[string]interface{}
142145

0 commit comments

Comments
 (0)