Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: creating an example test app #331

Merged
merged 19 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
coverage
*.log
.vscode
test
examples
test
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ app.start();
- Throwing an error (or returning a rejected promise) from the handler function will cause the message to be left on the queue. An [SQS redrive policy](http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/SQSDeadLetterQueue.html) can be used to move messages that cannot be processed to a dead letter queue.
- By default messages are processed one at a time – a new message won't be received until the first one has been processed. To process messages in parallel, use the `batchSize` option [detailed below](#options).

You can also find some examples of sqs-consumer implemented in various ways within the [examples directory](./examples/).

### Credentials

By default the consumer will look for AWS credentials in the places [specified by the AWS SDK](http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html#Setting_AWS_Credentials). The simplest option is to export your credentials as environment variables:
Expand Down
5 changes: 5 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SQS Consumer Example Apps

You'll find a number of example apps that can be used to try out SQS Consumer.

- [Simple Express App](./express-simple/)
31 changes: 31 additions & 0 deletions examples/express-simple/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# SQS Consumer Example App - Express Simple

This is an example app to show how SQS Consumer can be used, while also allowing us to test that the library is working correctly between changes, and with new functionality.

Please use this app when contributing changes to test your work with known functionality.

## Run the app

To get started, you will need Docker installed and started on your machine, you can [find instructions on how to install Docker here](https://docs.docker.com/get-docker/).

Once installed, just enter the command `npm run start` and after a few moments, the example app should be available at `http://localhost:3026`.

If you'd prefer to run without Docker, you can run the command `npm run start:node` instead.

> **Note**
> If you do not use the Docker stack, you will need to start a local version of SQS at `http://localhost:4566` or provide the location of your SQS Queue and your credentials using the environment variables that have been described below.

## Using the APIs

Once the app has started, a number of APIs will be made available for you to send a set of predefined sample requests.

You can find an [Insomnia export for these APIs here](./docs/Insomnia.json).

## Environment Variables

| Variable | Description |
| ----------------------- | -------------------------------------- |
| `SQS_ENDPOINT` | The SQS endpoint to use for your queue |
| `SQS_ACCESS_KEY_ID` | The access key for your queue |
| `SQS_SECRET_ACCESS_KEY` | The secret access key for your queue |
| `SQS_QUEUE_URL` | The URL of your queue |
34 changes: 34 additions & 0 deletions examples/express-simple/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: '3'
services:
localstack:
container_name: local_aws
hostname: local_aws
image: localstack/localstack:1.2.0@sha256:41216e34e25546654c58b8075b133027eab3d958e605ef2e7af168d1f05a9364
command: sh -c "/usr/local/bin/init.sh && exec myexecutable"
environment:
- AWS_DEFAULT_REGION=eu-west-2
- EDGE_PORT=4566
- SERVICES=sqs
- AWS_ACCESS_KEY_ID=key
- AWS_SECRET_ACCESS_KEY=secret
- DATA_DIR=/tmp/localstack/data
- HOST_TMP_FOLDER=${TMPDIR:-/tmp/}localstack
- DOCKER_HOST=unix:///var/run/docker.sock
- DEBUG=1
ports:
- "4566-4599:4566-4599"
volumes:
- '${TMPDIR:-/tmp/localstack}:/tmp/localstack'
- '/var/run/docker.sock:/var/run/docker.sock'
- ./localstack:/docker-entrypoint-initaws.d
networks:
sqs_c_example_net:
ipv4_address: 172.16.250.11

networks:
sqs_c_example_net:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.16.250.0/24
219 changes: 219 additions & 0 deletions examples/express-simple/docs/Insomnia.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
{
"_type": "export",
"__export_format": 4,
"__export_date": "2022-12-10T20:16:19.689Z",
"__export_source": "insomnia.desktop.app:v2022.6.0",
"resources": [
{
"_id": "req_9534f1040c86447e9728b3db4f272a18",
"parentId": "wrk_552b882fb639413db9c5dccf9f58e65d",
"modified": 1670703007921,
"created": 1670702995847,
"url": "http://localhost:3026/sample",
"name": "Send Sample",
"description": "",
"method": "POST",
"body": {},
"parameters": [],
"headers": [],
"authentication": {},
"metaSortKey": -1670702995847,
"isPrivate": false,
"settingStoreCookies": true,
"settingSendCookies": true,
"settingDisableRenderRequestBody": false,
"settingEncodeUrl": true,
"settingRebuildPath": true,
"settingFollowRedirects": "global",
"_type": "request"
},
{
"_id": "wrk_552b882fb639413db9c5dccf9f58e65d",
"parentId": null,
"modified": 1670702808564,
"created": 1670702808564,
"name": "New Document",
"description": "",
"scope": "design",
"_type": "workspace"
},
{
"_id": "req_bb7a8a6e5c7f40809ee0fd6ea0fa5ad2",
"parentId": "wrk_552b882fb639413db9c5dccf9f58e65d",
"modified": 1670703245783,
"created": 1670703238778,
"url": "http://localhost:3026/sample-with-fido",
"name": "Send Sample With FIDO",
"description": "",
"method": "POST",
"body": {},
"parameters": [],
"headers": [],
"authentication": {},
"metaSortKey": -1670702992122.25,
"isPrivate": false,
"settingStoreCookies": true,
"settingSendCookies": true,
"settingDisableRenderRequestBody": false,
"settingEncodeUrl": true,
"settingRebuildPath": true,
"settingFollowRedirects": "global",
"_type": "request"
},
{
"_id": "req_8a923e37301444139a68e03b1fb2a9af",
"parentId": "wrk_552b882fb639413db9c5dccf9f58e65d",
"modified": 1670703187946,
"created": 1670703175334,
"url": "http://localhost:3026/sample-with-delay",
"name": "Send Sample With Delay",
"description": "",
"method": "POST",
"body": {},
"parameters": [],
"headers": [],
"authentication": {},
"metaSortKey": -1670702988397.5,
"isPrivate": false,
"settingStoreCookies": true,
"settingSendCookies": true,
"settingDisableRenderRequestBody": false,
"settingEncodeUrl": true,
"settingRebuildPath": true,
"settingFollowRedirects": "global",
"_type": "request"
},
{
"_id": "req_ef9eba10937941f1963e95002a7c9215",
"parentId": "wrk_552b882fb639413db9c5dccf9f58e65d",
"modified": 1670703062037,
"created": 1670703057631,
"url": "http://localhost:3026/sample-with-attributes",
"name": "Send Sample With Attributes",
"description": "",
"method": "POST",
"body": {},
"parameters": [],
"headers": [],
"authentication": {},
"metaSortKey": -1670702980948,
"isPrivate": false,
"settingStoreCookies": true,
"settingSendCookies": true,
"settingDisableRenderRequestBody": false,
"settingEncodeUrl": true,
"settingRebuildPath": true,
"settingFollowRedirects": "global",
"_type": "request"
},
{
"_id": "req_f371381a5ca54281befbcba3c50f62f2",
"parentId": "wrk_552b882fb639413db9c5dccf9f58e65d",
"modified": 1670703043696,
"created": 1670703040091,
"url": "http://localhost:3026/sample-with-id",
"name": "Send Sample With ID",
"description": "",
"method": "POST",
"body": {},
"parameters": [],
"headers": [],
"authentication": {},
"metaSortKey": -1670702966049,
"isPrivate": false,
"settingStoreCookies": true,
"settingSendCookies": true,
"settingDisableRenderRequestBody": false,
"settingEncodeUrl": true,
"settingRebuildPath": true,
"settingFollowRedirects": "global",
"_type": "request"
},
{
"_id": "req_2b168104e6324115854ad75e080a087a",
"parentId": "wrk_552b882fb639413db9c5dccf9f58e65d",
"modified": 1670702982166,
"created": 1670702936251,
"url": "http://localhost:3026/queue-size",
"name": "Queue Size",
"description": "",
"method": "GET",
"body": {},
"parameters": [],
"headers": [],
"authentication": {},
"metaSortKey": -1670702936251,
"isPrivate": false,
"settingStoreCookies": true,
"settingSendCookies": true,
"settingDisableRenderRequestBody": false,
"settingEncodeUrl": true,
"settingRebuildPath": true,
"settingFollowRedirects": "global",
"_type": "request"
},
{
"_id": "req_946152c0a50f4ae28a60df61a75690ed",
"parentId": "wrk_552b882fb639413db9c5dccf9f58e65d",
"modified": 1670702946672,
"created": 1670702808575,
"url": "http://localhost:3026",
"name": "Home",
"description": "",
"method": "GET",
"body": {},
"parameters": [],
"headers": [],
"authentication": {},
"metaSortKey": -1670702808575,
"isPrivate": false,
"settingStoreCookies": true,
"settingSendCookies": true,
"settingDisableRenderRequestBody": false,
"settingEncodeUrl": true,
"settingRebuildPath": true,
"settingFollowRedirects": "global",
"_type": "request"
},
{
"_id": "env_273c62c358211bfabd1a6330da4f6ffaee16ffd9",
"parentId": "wrk_552b882fb639413db9c5dccf9f58e65d",
"modified": 1670702964727,
"created": 1670702808573,
"name": "Base Environment",
"data": {},
"dataPropertyOrder": {},
"color": null,
"isPrivate": false,
"metaSortKey": 1670702808573,
"_type": "environment"
},
{
"_id": "jar_273c62c358211bfabd1a6330da4f6ffaee16ffd9",
"parentId": "wrk_552b882fb639413db9c5dccf9f58e65d",
"modified": 1670702808574,
"created": 1670702808574,
"name": "Default Jar",
"cookies": [],
"_type": "cookie_jar"
},
{
"_id": "spc_dba2cdafc2724762a2646db6e33fc3fb",
"parentId": "wrk_552b882fb639413db9c5dccf9f58e65d",
"modified": 1670702932662,
"created": 1670702808571,
"fileName": "SQS Consumer Example App",
"contents": "",
"contentType": "yaml",
"_type": "api_spec"
},
{
"_id": "uts_7ffae42910fb478391b68d6c3ac67ffb",
"parentId": "wrk_552b882fb639413db9c5dccf9f58e65d",
"modified": 1670702808576,
"created": 1670702808576,
"name": "Example Test Suite",
"_type": "unit_test_suite"
}
]
}
17 changes: 17 additions & 0 deletions examples/express-simple/localstack/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

set -euo pipefail

echo "configuring localstack"
echo "==================="
LOCALSTACK_HOST=localhost
AWS_REGION=eu-west-1


# https://docs.aws.amazon.com/cli/latest/reference/sqs/create-queue.html
create_queue() {
local QUEUE_NAME_TO_CREATE=$1
awslocal --endpoint-url=http://${LOCALSTACK_HOST}:4566 sqs create-queue --queue-name ${QUEUE_NAME_TO_CREATE} --region ${AWS_REGION} --attributes VisibilityTimeout=30
}

create_queue "sqs-consumer-data"
12 changes: 12 additions & 0 deletions examples/express-simple/node/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:16

COPY package.json .
COPY tsconfig.json .

RUN npm install

RUN npm run build

COPY . .

CMD ["npm", "run start"]
Loading