Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Amazon MQ event structure (#346)
* Add Amazon MQ event structure * Formatted * apply not-enforced naming conventions * EventSourceArn -> EventSourceARN * Destination -> ActiveMQDestination Co-authored-by: Bryan Moffatt <bmoffatt@users.noreply.github.com> Co-authored-by: Bryan Moffatt <moffattb@amazon.com>
- Loading branch information
1 parent
70e75f4
commit 6dcfd20
Showing
3 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
package events | ||
|
||
type ActiveMQEvent struct { | ||
EventSource string `json:"eventSource"` | ||
EventSourceARN string `json:"eventSourceArn"` | ||
Messages []ActiveMQMessage `json:"messages"` | ||
} | ||
|
||
type ActiveMQMessage struct { | ||
MessageID string `json:"messageID"` | ||
MessageType string `json:"messageType"` | ||
Timestamp int64 `json:"timestamp"` | ||
DeliveryMode int `json:"deliveryMode"` | ||
CorrelationID string `json:"correlationID"` | ||
ReplyTo string `json:"replyTo"` | ||
Destination ActiveMQDestination `json:"destination"` | ||
Redelivered bool `json:"redelivered"` | ||
Type string `json:"type"` | ||
Expiration int64 `json:"expiration"` | ||
Priority int `json:"priority"` | ||
Data string `json:"data"` | ||
BrokerInTime int64 `json:"brokerInTime"` | ||
BrokerOutTime int64 `json:"brokerOutTime"` | ||
} | ||
|
||
type ActiveMQDestination struct { | ||
PhysicalName string `json:"physicalName"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
package events | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/aws/aws-lambda-go/events/test" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestActiveMQEventMarshaling(t *testing.T) { | ||
// 1. read JSON from file | ||
inputJson := test.ReadJSONFromFile(t, "./testdata/activemq-event.json") | ||
|
||
// 2. de-serialize into Go object | ||
var inputEvent ActiveMQEvent | ||
if err := json.Unmarshal(inputJson, &inputEvent); err != nil { | ||
t.Errorf("could not unmarshal event. details: %v", err) | ||
} | ||
|
||
// 3. Verify values populated into Go Object, at least one validation per data type | ||
assert.Equal(t, "aws:mq", inputEvent.EventSource) | ||
assert.Equal(t, "arn:aws:mq:us-west-2:533019413397:broker:shask-test:b-0f5b7522-2b41-4f85-a615-735a4e6d96b5", inputEvent.EventSourceARN) | ||
assert.Equal(t, 1, len(inputEvent.Messages)) | ||
|
||
var message = inputEvent.Messages[0] | ||
assert.Equal(t, "jms/text-message", message.MessageType) | ||
assert.Equal(t, int64(1599863938941), message.Timestamp) | ||
assert.Equal(t, 1, message.DeliveryMode) | ||
assert.Equal(t, "testQueue", message.Destination.PhysicalName) | ||
assert.Equal(t, false, message.Redelivered) | ||
|
||
// 4. serialize to JSON | ||
outputJson, err := json.Marshal(inputEvent) | ||
if err != nil { | ||
t.Errorf("could not marshal event. details: %v", err) | ||
} | ||
|
||
// 5. check result | ||
assert.JSONEq(t, string(inputJson), string(outputJson)) | ||
} | ||
|
||
func TestActiveMQMarshalingMalformedJson(t *testing.T) { | ||
test.TestMalformedJson(t, ActiveMQEvent{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"eventSource": "aws:mq", | ||
"eventSourceArn": "arn:aws:mq:us-west-2:533019413397:broker:shask-test:b-0f5b7522-2b41-4f85-a615-735a4e6d96b5", | ||
"messages": [ | ||
{ | ||
"messageID": "ID:b-0f5b7522-2b41-4f85-a615-735a4e6d96b5-2.mq.us-west-2.amazonaws.com-34859-1598944546501-4:12:1:1:3", | ||
"messageType": "jms/text-message", | ||
"timestamp": 1599863938941, | ||
"deliveryMode": 1, | ||
"correlationID": "", | ||
"replyTo": "null", | ||
"destination": { | ||
"physicalName": "testQueue" | ||
}, | ||
"redelivered": false, | ||
"type": "", | ||
"expiration": 0, | ||
"priority": 0, | ||
"data": "RW50ZXIgc29tZSB0ZXh0IGhlcmUgZm9yIHRoZSBtZXNzYWdlIGJvZHkuLi4=", | ||
"brokerInTime": 1599863938943, | ||
"brokerOutTime": 1599863938944 | ||
} | ||
] | ||
} |