-
Notifications
You must be signed in to change notification settings - Fork 98
Support for multiple data sections #38
Comments
I prefer |
I implemented I'm not sold on the approach. Taking the case of batching, presumably it's possible for a batch to contain only a single data payload. In that case it would end up in the Going to think on this a bit longer to see if I (or anyone else) come up with a better approach. |
I'm starting to think changing The reason I didn't want to change This can be mitigating by providing an accessor method like: func (m *Message) GetData() []byte {
if len(m.Data) < 1 {
return nil
}
return m.Data[0]
} Then the consumer can do Other than the breaking change, I don't see a significant downside to this approach. |
I updated the multidata branch with my latest idea for this API. An unfortunate side effect of this approach is that constructing a message with a single payload requires a little more work. msg := &amqp.Message{
Data: data,
} becomes msg := &amqp.Message{
Data: [][]byte{data},
} To mitigate this I've added a constructor function: // NewMessage returns a *Message with data as the payload.
//
// This constructor is intended as a helper for basic messages with a
// single data payload. It is valid to construct a message directly for
// more complex usages.
func NewMessage(data []byte) *Message {
return &Message{
Data: [][]byte{data},
}
} Since I don't personally use the sending functionality of this lib outside it's own integration tests, I'm not sure how useful the constructor will be in practice. |
Per discussion in #35, multiple data section support would be helpful for some use cases.
The implementation shouldn't be too difficult, but I'm not sure how the API should look.
Though not a firm requirement, I'd like to leave
Message.Data
as is. I suspect a single data payload is the most common case.Idea A: Add an
AdditionalData [][]byte
field.Message.Data
andMessage.AdditionalData
, which isn't particularly ergonomic but I don't think it's terrible either.Idea B: Add
MultiData [][]byte
, where the first element is the same same asMessage.Data
.Message.Data
orMessage.MultiData
instead of both.Message.Data
andMessage.MultiData
where the firstMultiData
element differs fromData
. The API would likely end up asymmetric.Idea C: A variation on the above
MultiData [][]byte
approach could be to only setData
orMultiData
.After rubber-ducking in this issue, I'm favoring Idea C. Other input is welcome.
/cc @devigned
The text was updated successfully, but these errors were encountered: