Skip to content

Commit 6dcfd20

Browse files
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>
1 parent 70e75f4 commit 6dcfd20

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

events/activemq.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
3+
package events
4+
5+
type ActiveMQEvent struct {
6+
EventSource string `json:"eventSource"`
7+
EventSourceARN string `json:"eventSourceArn"`
8+
Messages []ActiveMQMessage `json:"messages"`
9+
}
10+
11+
type ActiveMQMessage struct {
12+
MessageID string `json:"messageID"`
13+
MessageType string `json:"messageType"`
14+
Timestamp int64 `json:"timestamp"`
15+
DeliveryMode int `json:"deliveryMode"`
16+
CorrelationID string `json:"correlationID"`
17+
ReplyTo string `json:"replyTo"`
18+
Destination ActiveMQDestination `json:"destination"`
19+
Redelivered bool `json:"redelivered"`
20+
Type string `json:"type"`
21+
Expiration int64 `json:"expiration"`
22+
Priority int `json:"priority"`
23+
Data string `json:"data"`
24+
BrokerInTime int64 `json:"brokerInTime"`
25+
BrokerOutTime int64 `json:"brokerOutTime"`
26+
}
27+
28+
type ActiveMQDestination struct {
29+
PhysicalName string `json:"physicalName"`
30+
}

events/activemq_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
package events
3+
4+
import (
5+
"encoding/json"
6+
"testing"
7+
8+
"github.com/aws/aws-lambda-go/events/test"
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestActiveMQEventMarshaling(t *testing.T) {
13+
// 1. read JSON from file
14+
inputJson := test.ReadJSONFromFile(t, "./testdata/activemq-event.json")
15+
16+
// 2. de-serialize into Go object
17+
var inputEvent ActiveMQEvent
18+
if err := json.Unmarshal(inputJson, &inputEvent); err != nil {
19+
t.Errorf("could not unmarshal event. details: %v", err)
20+
}
21+
22+
// 3. Verify values populated into Go Object, at least one validation per data type
23+
assert.Equal(t, "aws:mq", inputEvent.EventSource)
24+
assert.Equal(t, "arn:aws:mq:us-west-2:533019413397:broker:shask-test:b-0f5b7522-2b41-4f85-a615-735a4e6d96b5", inputEvent.EventSourceARN)
25+
assert.Equal(t, 1, len(inputEvent.Messages))
26+
27+
var message = inputEvent.Messages[0]
28+
assert.Equal(t, "jms/text-message", message.MessageType)
29+
assert.Equal(t, int64(1599863938941), message.Timestamp)
30+
assert.Equal(t, 1, message.DeliveryMode)
31+
assert.Equal(t, "testQueue", message.Destination.PhysicalName)
32+
assert.Equal(t, false, message.Redelivered)
33+
34+
// 4. serialize to JSON
35+
outputJson, err := json.Marshal(inputEvent)
36+
if err != nil {
37+
t.Errorf("could not marshal event. details: %v", err)
38+
}
39+
40+
// 5. check result
41+
assert.JSONEq(t, string(inputJson), string(outputJson))
42+
}
43+
44+
func TestActiveMQMarshalingMalformedJson(t *testing.T) {
45+
test.TestMalformedJson(t, ActiveMQEvent{})
46+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"eventSource": "aws:mq",
3+
"eventSourceArn": "arn:aws:mq:us-west-2:533019413397:broker:shask-test:b-0f5b7522-2b41-4f85-a615-735a4e6d96b5",
4+
"messages": [
5+
{
6+
"messageID": "ID:b-0f5b7522-2b41-4f85-a615-735a4e6d96b5-2.mq.us-west-2.amazonaws.com-34859-1598944546501-4:12:1:1:3",
7+
"messageType": "jms/text-message",
8+
"timestamp": 1599863938941,
9+
"deliveryMode": 1,
10+
"correlationID": "",
11+
"replyTo": "null",
12+
"destination": {
13+
"physicalName": "testQueue"
14+
},
15+
"redelivered": false,
16+
"type": "",
17+
"expiration": 0,
18+
"priority": 0,
19+
"data": "RW50ZXIgc29tZSB0ZXh0IGhlcmUgZm9yIHRoZSBtZXNzYWdlIGJvZHkuLi4=",
20+
"brokerInTime": 1599863938943,
21+
"brokerOutTime": 1599863938944
22+
}
23+
]
24+
}

0 commit comments

Comments
 (0)