Skip to content

Commit 1b60ba2

Browse files
committed
fix: documentation and utilities
1 parent 544e1e9 commit 1b60ba2

File tree

4 files changed

+55
-10
lines changed

4 files changed

+55
-10
lines changed

interfaces/delayfn.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package interfaces
22

3+
// DelayFn is a function type that represents a delay function.
4+
// It takes the current number of retries as input and returns the delay in seconds.
35
type DelayFn func(currenRetries int64) (delay int64)
46

57
var (
@@ -19,5 +21,7 @@ var (
1921
NoDelayFn DelayFn = func(currenRetries int64) (delay int64) {
2022
return 0
2123
}
24+
// DefaultDelayFn is the default delay function that will be used if no delay function is provided.
25+
// It is set to LinearDelayFn by default.
2226
DefaultDelayFn DelayFn = LinearDelayFn
2327
)

interfaces/inboundmessagehandler.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ type InboundMessageHandlerMiddlewareFunc func(next InboundMessageHandlerFunc) In
1717

1818
type InboundMessage struct {
1919
Message
20-
RetryCount int64 `json:"retryCount"`
21-
Metadata map[string]interface{} `json:"metadata"`
20+
// RetryCount is the number of times the message has been retried.
21+
// This is set by the library to identify the number of times the message has been retried.
22+
RetryCount int64 `json:"retryCount"`
23+
// Metadata is the metadata of the message.
24+
// This is set by the library to identify the metadata of the message.
25+
Metadata map[string]interface{} `json:"metadata"`
2226
// Ack is used for confirming the message. It will drop the message from the queue.
2327
Ack func(ctx context.Context) (err error) `json:"-"`
2428
// Nack is used for rejecting the message. It will requeue the message to be re-delivered again.

interfaces/message.go

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,56 @@ import (
1212
// The message is used to publish messages to the queue.
1313
// Read the concept of message publishing in the documentation, here: TODO(bxcodec): Add link to the documentation
1414
type Message struct {
15-
ID string `json:"id"`
16-
Action string `json:"action"`
17-
Topic string `json:"topic"`
18-
Data any `json:"data"`
19-
ContentType headerVal.ContentType `json:"-"`
20-
Timestamp time.Time `json:"timestamp"`
21-
Headers map[string]interface{} `json:"-"`
22-
ServiceAgent headerVal.GoquServiceAgent `json:"-"`
15+
// ID is the unique identifier for the message.
16+
// This is set by the publisher to identify the message in the queue.
17+
// The id is auto-generated by the the library if not provided.
18+
ID string `json:"id"`
19+
// Action is the action that will be performed on the message.
20+
// This is set by the publisher to identify the action that will be performed on the message.
21+
// For RabbitMQ, the action is the routing key.
22+
Action string `json:"action"`
23+
// Topic is the topic that the message will be published to.
24+
// This is set by the publisher to identify the topic that the message will be published to.
25+
// For RabbitMQ, the topic is the exchange name.
26+
Topic string `json:"topic"`
27+
// Data is the data that will be published to the queue.
28+
// This is set by the publisher to identify the data that will be published to the queue.
29+
// It should be a valid JSON object.
30+
Data any `json:"data"`
31+
// ContentType is the content type of the message.
32+
// This is set by the publisher to identify the content type of the message.
33+
// Default value is "application/json".
34+
ContentType headerVal.ContentType `json:"-"`
35+
// Timestamp is the timestamp of the message.
36+
// This is set by the publisher to identify the timestamp of the message.
37+
// Default value is the current time.
38+
Timestamp time.Time `json:"timestamp"`
39+
// Headers is the headers of the message.
40+
// This is set by the publisher to identify the headers of the message.
41+
// This library will provide extra headers values by default based on the library type.
42+
// Don't use any prefix with :goqueue-, it will conflicted and overrided by the library.
43+
Headers map[string]interface{} `json:"-"`
44+
// ServiceAgent is the service agent that will be used to publish the message.
45+
// This is set by the publisher to identify the service agent that will be used to publish the message.
46+
// This will be set by the library and override any value
47+
ServiceAgent headerVal.GoquServiceAgent `json:"-"`
48+
// SchemaVersion is the schema version of the message.
49+
// This is set by the publisher to identify the schema version of the message.
50+
// Default value is the library type.
51+
// This will be set by the library and override any value
2352
schemaVersion string
2453
}
2554

55+
// SetSchemaVersion is a method to set the schema version of the message.
56+
// This is used to set the schema version of the message.
57+
// This will be set by the library and override any value
2658
func (m *Message) SetSchemaVersion(v string) {
2759
m.schemaVersion = v
2860
}
2961

62+
// GetSchemaVersion is a method to get the schema version of the message.
63+
// This is used to get the schema version of the message.
64+
// This will be set by the library and override any value
3065
func (m *Message) GetSchemaVersion() string {
3166
return m.schemaVersion
3267
}

interfaces/publisher.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ func (f PublisherFunc) Publish(ctx context.Context, m Message) (err error) {
2020
return f(ctx, m)
2121
}
2222

23+
// PublisherMiddlewareFunc is a function type that represents a publisher middleware function.
24+
// It takes a next PublisherFunc as input parameter and returns a PublisherFunc.
2325
type PublisherMiddlewareFunc func(next PublisherFunc) PublisherFunc

0 commit comments

Comments
 (0)