From 936d5a7b5a56a24989c03bb987a8cc1b26bf7f75 Mon Sep 17 00:00:00 2001 From: klutzer Date: Tue, 22 Nov 2022 18:17:11 -0300 Subject: [PATCH 1/3] Add fifo queue support --- frontend/components/SendMessageDialog.tsx | 17 +++++++++++++++++ frontend/types/index.tsx | 1 + server/aws/sqsClient.go | 7 +++++++ server/aws/types/types.go | 1 + server/go.mod | 1 + server/go.sum | 2 ++ 6 files changed, 29 insertions(+) diff --git a/frontend/components/SendMessageDialog.tsx b/frontend/components/SendMessageDialog.tsx index f68eeef9..3d303f8b 100644 --- a/frontend/components/SendMessageDialog.tsx +++ b/frontend/components/SendMessageDialog.tsx @@ -13,10 +13,12 @@ import { SendMessageDialogProps } from "../types"; const SendMessageDialog = (props: SendMessageDialogProps) => { const [open, setOpen] = useState(false); const [messageBody, setMessageBody] = useState(""); + const [messageGroupId, setMessageGroupId] = useState(""); const handleClickOpen = () => { setMessageBody(""); setOpen(true); + setMessageGroupId(""); }; const handleClose = () => { @@ -27,9 +29,14 @@ const SendMessageDialog = (props: SendMessageDialogProps) => { setMessageBody(event.target.value); }; + const handleGroupIdChange = (event: React.ChangeEvent) => { + setMessageGroupId(event.target.value); + }; + const submitSendRequest = () => { props.onSubmit({ messageBody: messageBody, + messageGroupId: messageGroupId === "" ? undefined : messageGroupId, }); handleClose(); }; @@ -60,6 +67,16 @@ const SendMessageDialog = (props: SendMessageDialogProps) => { onChange={handleChange} variant="standard" /> + diff --git a/frontend/types/index.tsx b/frontend/types/index.tsx index 45516493..2088f3ba 100644 --- a/frontend/types/index.tsx +++ b/frontend/types/index.tsx @@ -32,6 +32,7 @@ export interface SqsMessage { messageBody: string; messageId?: string; messageAttributes?: { [key: string]: string } | undefined; + messageGroupId?: string; } export interface ApiCall { diff --git a/server/aws/sqsClient.go b/server/aws/sqsClient.go index 69af0d53..e2916bef 100644 --- a/server/aws/sqsClient.go +++ b/server/aws/sqsClient.go @@ -7,6 +7,7 @@ import ( "github.com/pacoVK/aws/types" "log" "strings" + "github.com/google/uuid" ) func getQueues() (*sqs.ListQueuesOutput, error) { @@ -88,8 +89,14 @@ func CreateQueue(queueName string) (*sqs.CreateQueueOutput, error) { } func SendMessage(queueUrl string, sqsMessage types.SqsMessage) (*sqs.SendMessageOutput, error) { + deduplicationId := sqsMessage.MessageGroupId + if len(deduplicationId) > 0 { + deduplicationId = uuid.New().String() + } return sqsClient.SendMessage(context.TODO(), &sqs.SendMessageInput{ QueueUrl: &queueUrl, MessageBody: &sqsMessage.MessageBody, + MessageGroupId: &sqsMessage.MessageGroupId, + MessageDeduplicationId: &deduplicationId, }) } diff --git a/server/aws/types/types.go b/server/aws/types/types.go index 52be5985..c218e90a 100644 --- a/server/aws/types/types.go +++ b/server/aws/types/types.go @@ -10,6 +10,7 @@ type SqsMessage struct { MessageId string `json:"messageId"` MessageBody string `json:"messageBody"` MessageAttributes map[string]string `json:"messageAttributes"` + MessageGroupId string `json:"messageGroupId,omitempty"` } type Request struct { diff --git a/server/go.mod b/server/go.mod index ae77b0ce..304e540d 100644 --- a/server/go.mod +++ b/server/go.mod @@ -22,4 +22,5 @@ require ( github.com/aws/aws-sdk-go-v2/service/sts v1.17.1 // indirect github.com/aws/smithy-go v1.13.4 // indirect github.com/felixge/httpsnoop v1.0.1 // indirect + github.com/google/uuid v1.3.0 // indirect ) diff --git a/server/go.sum b/server/go.sum index 1b8923b1..c8ac43d2 100644 --- a/server/go.sum +++ b/server/go.sum @@ -29,6 +29,8 @@ github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8S github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4= github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= From 54dda93e1aec42ab6205ac64126190ba9a1b52b2 Mon Sep 17 00:00:00 2001 From: Pascal Euhus Date: Wed, 23 Nov 2022 16:05:31 +0100 Subject: [PATCH 2/3] Support Fifo queues --- frontend/components/CreateQueueDialog.tsx | 43 ++++++++++++++++++++--- frontend/components/SendMessageDialog.tsx | 6 ++++ frontend/types/index.tsx | 6 ++-- frontend/views/Overview.tsx | 17 ++++++--- server/aws/sqsClient.go | 13 +++---- server/handler/sqsHandler.go | 4 +-- server/handler/sqsHandler_test.go | 6 ++-- 7 files changed, 73 insertions(+), 22 deletions(-) diff --git a/frontend/components/CreateQueueDialog.tsx b/frontend/components/CreateQueueDialog.tsx index 5bafa634..83fe6eac 100644 --- a/frontend/components/CreateQueueDialog.tsx +++ b/frontend/components/CreateQueueDialog.tsx @@ -1,21 +1,26 @@ import React, { useState } from "react"; import { Button, + Checkbox, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, + FormControlLabel, + FormGroup, TextField, } from "@mui/material"; -import { CreateQueueDialogProps } from "../types"; +import { CreateQueueDialogProps, Queue } from "../types"; const CreateQueueDialog = (props: CreateQueueDialogProps) => { const [open, setOpen] = useState(false); const [queueName, setQueueName] = useState(""); + const [isFifoQueue, enableFifoQueue] = useState(false); const handleClickOpen = () => { setQueueName(""); + enableFifoQueue(false); setOpen(true); }; @@ -23,12 +28,30 @@ const CreateQueueDialog = (props: CreateQueueDialogProps) => { setOpen(false); }; - const handleChange = (event: React.ChangeEvent) => { + const handleChangeQueueName = ( + event: React.ChangeEvent + ) => { setQueueName(event.target.value); }; + const handleChangeFifoSwitch = ( + event: React.ChangeEvent + ) => { + enableFifoQueue(event.target.checked); + }; + const submitCreateQueue = () => { - props.onSubmit(queueName); + let sanitizedQueueName = queueName; + if (isFifoQueue && !queueName.endsWith(".fifo")) { + sanitizedQueueName = `${sanitizedQueueName}.fifo`; + } + const newQueue: Queue = { + QueueName: sanitizedQueueName, + QueueAttributes: { + FifoQueue: `${isFifoQueue}`, + }, + }; + props.onSubmit(newQueue); handleClose(); }; @@ -51,9 +74,21 @@ const CreateQueueDialog = (props: CreateQueueDialogProps) => { type="text" fullWidth value={queueName} - onChange={handleChange} + onChange={handleChangeQueueName} variant="standard" /> + + + } + label="FIFO Queue" + /> + diff --git a/frontend/components/SendMessageDialog.tsx b/frontend/components/SendMessageDialog.tsx index 3d303f8b..050e27e8 100644 --- a/frontend/components/SendMessageDialog.tsx +++ b/frontend/components/SendMessageDialog.tsx @@ -73,8 +73,14 @@ const SendMessageDialog = (props: SendMessageDialogProps) => { label="Message-Group-Id" type="text" fullWidth + required={true} value={messageGroupId} onChange={handleGroupIdChange} + style={{ + display: props.queue?.QueueName.endsWith(".fifo") + ? "flex" + : "none", + }} variant="standard" /> diff --git a/frontend/types/index.tsx b/frontend/types/index.tsx index 2088f3ba..7893fbef 100644 --- a/frontend/types/index.tsx +++ b/frontend/types/index.tsx @@ -1,5 +1,4 @@ import { AlertColor } from "@mui/material"; -import { MessageAttributeValue } from "@aws-sdk/client-sqs"; export interface TabPanelProps { children?: React.ReactNode; @@ -8,12 +7,13 @@ export interface TabPanelProps { } export interface CreateQueueDialogProps { - onSubmit: (queueName: string) => void; + onSubmit: (queue: Queue) => void; } export interface SendMessageDialogProps { onSubmit: (message: SqsMessage) => void; disabled: boolean; + queue: Queue; } export interface AlertProps { @@ -23,8 +23,8 @@ export interface AlertProps { } export interface Queue { - QueueUrl: string; QueueName: string; + QueueUrl?: string; QueueAttributes?: { [key: string]: string } | undefined; } diff --git a/frontend/views/Overview.tsx b/frontend/views/Overview.tsx index ffbb69ca..01d57b69 100644 --- a/frontend/views/Overview.tsx +++ b/frontend/views/Overview.tsx @@ -78,14 +78,11 @@ const Overview = () => { } }; - const createNewQueue = async (queueName: string) => { + const createNewQueue = async (queue: Queue) => { await callApi({ method: "POST", action: "CreateQueue", - queue: { - QueueUrl: "", - QueueName: queueName, - }, + queue: queue, onSuccess: () => { setTimeout(() => { triggerReload(!reload); @@ -125,6 +122,15 @@ const Overview = () => { const sendMessageToCurrentQueue = async (message: SqsMessage) => { let queueUrl = queues[tabIndex]?.QueueUrl || null; if (queueUrl !== null) { + if ( + queues[tabIndex]?.QueueName.endsWith(".fifo") && + !message.messageGroupId + ) { + setError( + "You need to set a MessageGroupID when sending Messages to a FIFO queue" + ); + return; + } await callApi({ method: "POST", action: "SendMessage", @@ -163,6 +169,7 @@ const Overview = () => {