@@ -6,16 +6,24 @@ import (
6
6
"github.com/google/uuid"
7
7
)
8
8
9
+ // ProducerOptions holds configuration options for a Producer.
9
10
type ProducerOptions struct {
11
+ // IDGenerator is function that generates a unique identifier for each message produced by the Producer.
12
+ // The default ID generator is uuid.NewString.
10
13
IDGenerator func () string
11
14
}
12
15
16
+ // WithIDGenerator is an option function to set a custom ID generator for the Producer.
17
+ // Use this function to provide a custom function that generates unique identifiers for messages.
18
+ // The default ID generator is uuid.NewString.
13
19
func WithIDGenerator (idGenerator func () string ) func (o * ProducerOptions ) {
14
20
return func (o * ProducerOptions ) {
15
21
o .IDGenerator = idGenerator
16
22
}
17
23
}
18
24
25
+ // NewProducer creates a new instance of a Producer, which is used to produce messages to a DynamoDB-based queue.
26
+ // The Producer can be configured with various options, such as a custom ID generator.
19
27
func NewProducer [T any ](client Client [T ], opts ... func (o * ProducerOptions )) * Producer [T ] {
20
28
o := & ProducerOptions {
21
29
IDGenerator : uuid .NewString ,
@@ -29,20 +37,29 @@ func NewProducer[T any](client Client[T], opts ...func(o *ProducerOptions)) *Pro
29
37
}
30
38
}
31
39
40
+ // Producer is a generic struct responsible for producing messages of any type T to a DynamoDB-based queue.
32
41
type Producer [T any ] struct {
33
42
client Client [T ]
34
43
idGenerator func () string
35
44
}
36
45
46
+ // ProduceInput represents the input parameters for producing a message.
37
47
type ProduceInput [T any ] struct {
38
- Data T
48
+ // Data is the content of the message to be produced. The type T allows for flexibility in the data type of the message payload.
49
+ Data T
50
+ // DelaySeconds is the delay time (in seconds) before the message is sent to the queue.
39
51
DelaySeconds int
40
52
}
41
53
54
+ // ProduceOutput represents the result of the produce operation.
42
55
type ProduceOutput [T any ] struct {
56
+ // Message is a pointer to the Message type containing information about the produced message.
43
57
Message * Message [T ]
44
58
}
45
59
60
+ // Produce sends a message to the queue using the provided input parameters.
61
+ // It generates a unique ID for the message using the Producer's ID generator and delegates to the Client's SendMessage method.
62
+ // An error is returned if the SendMessage operation fails.
46
63
func (c * Producer [T ]) Produce (ctx context.Context , params * ProduceInput [T ]) (* ProduceOutput [T ], error ) {
47
64
if params == nil {
48
65
params = & ProduceInput [T ]{}
0 commit comments