Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Commit

Permalink
Merge pull request #173 from sul-dlss/sqs
Browse files Browse the repository at this point in the history
Switches to SQS from SNS.
  • Loading branch information
aaron-collier authored Jan 31, 2019
2 parents a96f1e3 + 44b66e4 commit 09a31a4
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 19 deletions.
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

[[constraint]]
name = "github.com/aws/aws-lambda-go"
version = "1.2.0"
version = "1.8.2"

[prune]
go-tests = true
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![CircleCI](https://circleci.com/gh/sul-dlss/rialto-derivatives.svg?style=svg)](https://circleci.com/gh/sul-dlss/rialto-derivatives)

This project contains Lambda functions that migrate data from Neptune to Solr and Postgres
when an appropriately formatted SNS message is received. In the RIALTO architecture these messages come from https://github.com/sul-dlss/rialto-trigger-rebuild when a full rebuild is needed or from https://github.com/sul-dlss/sparql-loader when a single entity needs to be updated.
when an appropriately formatted SQS message is received. In the RIALTO architecture these messages come from https://github.com/sul-dlss/rialto-trigger-rebuild when a full rebuild is needed or from https://github.com/sul-dlss/sparql-loader when a single entity needs to be updated.

## Running a lambda on localstack

Expand All @@ -11,7 +11,7 @@ when an appropriately formatted SNS message is received. In the RIALTO architect
Start [localstack](https://github.com/localstack/localstack#installing). If you're on a Mac, ensure you are running the docker daemon.

```
SERVICES=lambda,sns LAMBDA_EXECUTOR=docker localstack start
SERVICES=lambda,sns,sqs LAMBDA_EXECUTOR=docker localstack start
```

### Blazegraph
Expand Down
4 changes: 2 additions & 2 deletions cmd/postgres/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import (
)

// Handler is the Lambda function handler
func Handler(ctx context.Context, snsEvent events.SNSEvent) {
func Handler(ctx context.Context, sqsEvent events.SQSEvent) {
repo := repository.BuildRepository()
registry := runtime.NewRegistry(repo, buildDatabase(repo))
for _, record := range snsEvent.Records {
for _, record := range sqsEvent.Records {
msg, err := message.Parse(record)
if err != nil {
panic(err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/solr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
)

// Handler is the Lambda function handler
func Handler(ctx context.Context, snsEvent events.SNSEvent) {
func Handler(ctx context.Context, sqsEvent events.SQSEvent) {
repo := repository.BuildRepository()
registry := runtime.NewRegistry(repo, buildSolrClient(repo))
for _, record := range snsEvent.Records {
for _, record := range sqsEvent.Records {
msg, err := message.Parse(record)
if err != nil {
panic(err)
Expand Down
19 changes: 14 additions & 5 deletions message/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,27 @@ import (
"github.com/aws/aws-lambda-go/events"
)

// Message a message (from SNS) that the application understands
// Message a message (from SQS) that the application understands
type Message struct {
Action string
Entities []string
Body interface{}
}

// Parse transforms a SNSEventRecord into a message
func Parse(record events.SNSEventRecord) (*Message, error) {
data := record.SNS.Message
// SQSBody is the body of an SQS message
type SQSBody struct {
Message string
}

// Parse transforms an SQSMessage into a message
func Parse(record events.SQSMessage) (*Message, error) {
body := &SQSBody{}
err := json.Unmarshal([]byte(record.Body), body)
if err != nil {
return nil, err
}
msg := &Message{}
err := json.Unmarshal([]byte(data), msg)
err = json.Unmarshal([]byte(body.Message), msg)
if err != nil {
return nil, err
}
Expand Down
7 changes: 3 additions & 4 deletions message/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import (
)

func TestParse(t *testing.T) {
evtRecord := events.SNSEventRecord{
SNS: events.SNSEntity{
Message: "{\"Action\": \"touch\", \"Entities\":[\"http://example.com/foo1\"] }",
},
evtRecord := events.SQSMessage{
Body: "{\"Message\": \"{\\\"Action\\\": \\\"touch\\\", \\\"Entities\\\":[\\\"http://example.com/foo1\\\"] }\"}",
}

event, _ := Parse(evtRecord)
assert.Equal(t, "touch", event.Action)
assert.Equal(t, []string{"http://example.com/foo1"}, event.Entities)
Expand Down

0 comments on commit 09a31a4

Please sign in to comment.