<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Gavin Dang</title>
    <description>The latest articles on DEV Community by Gavin Dang (@gavindang2911).</description>
    <link>https://dev.to/gavindang2911</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F420274%2F126872a1-799d-4ae2-a79a-7ca0628c42fa.png</url>
      <title>DEV Community: Gavin Dang</title>
      <link>https://dev.to/gavindang2911</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gavindang2911"/>
    <language>en</language>
    <item>
      <title>AWS SQS</title>
      <dc:creator>Gavin Dang</dc:creator>
      <pubDate>Thu, 05 Sep 2024 22:44:04 +0000</pubDate>
      <link>https://dev.to/gavindang2911/aws-sqs-3gp3</link>
      <guid>https://dev.to/gavindang2911/aws-sqs-3gp3</guid>
      <description>&lt;p&gt;&lt;strong&gt;Amazon Simple Queue Service (SQS)&lt;/strong&gt; is a distributed message queuing service introduced by Amazon Web Services (AWS) in 2004. It allows you to send and receive messages through an HTTP API over the internet. Designed with high scalability in mind, SQS facilitates seamless message exchange between different components of a system.&lt;/p&gt;

&lt;p&gt;Key Features of SQS: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;High Scalability: SQS scales automatically based on message read/write capacity, eliminating the need to manage queue scaling manually—AWS handles this for you.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pay-as-You-Go Pricing: You only pay for the number of read/write operations you perform, with no recurring fees.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Easy Setup: There is no need to set up any infrastructure to use SQS. You simply call the API to read or write messages.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Standard and FIFO Queues: SQS offers two types of queues: Standard and FIFO. You can choose the type that best suits your needs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Automatic Deduplication in FIFO Queues: SQS automatically handles duplicate messages in FIFO queues. This ensures that tasks are executed only once, making FIFO queues ideal for processes where each task should be executed exactly once.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Error Handling with Dead Letter Queues (DLQs): A critical feature for debugging, DLQs store messages that could not be processed successfully. You can inspect and handle failed messages separately from the main queue.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How Does SQS Work?
&lt;/h2&gt;

&lt;p&gt;Behind the Scenes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Queue Operation: Typically, a queue operates by having producers send messages to it. Consumers then retrieve and process these messages. The system tracks messages as pending or in-flight and delivers them to consumers. Background jobs at the consumer end process these messages.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Message Processing: Once a consumer finishes processing a message, it sends an acknowledgment to the queue to confirm successful processing. The message status changes from pending to processed. If the acknowledgment is not received within a certain time frame, the message is considered not processed and is made available to other consumers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Handling Failures: If processing fails after a specified number of retries, the message is either stopped from being sent to consumers or moved to a Dead Letter Queue (DLQ) for further analysis.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Overall
&lt;/h2&gt;

&lt;p&gt;The operation of AWS SQS is straightforward. When an application or system needs to send a message, it places the message into an SQS queue. The message remains in the queue until another process, known as a "consumer," retrieves it for processing.&lt;/p&gt;

&lt;p&gt;For instance, if you are developing a bulk email sending application, you can utilize SQS to manage email sending requests. Each request is added to the SQS queue, and a separate process retrieves and processes these requests to send the emails.&lt;/p&gt;

&lt;h2&gt;
  
  
  With SQS:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;SQS provides an API endpoint for producers to send messages and for consumers to read and process them.
Messages sent to SQS can be in any format, including strings, XML, or JSON.&lt;/li&gt;
&lt;li&gt;There is no limit to the number of messages that can be sent or processed by SQS.&lt;/li&gt;
&lt;li&gt;Example Message Structure:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here’s what a message in SQS might look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;message_id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a123d234g-82451-4qwf-a2f36-ee2135as25td&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;receipt_handle&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;AQEBLVo6YHmeJXe2np4Dz7Yf0UpRsIoM5Nk9T7W1jC/LuPp9ZG9b8QJv6EZo8L5XbKQ1dIn4yqV9G0YkCwH3j0TNRhM1gIb5LBcL2R1HrAo8ZLkH1lBG9ZPXTpG2bCu7HjpQK/lQ5Z8r1kLg+V8dV0b9mJ4CpF4Pne/Ay7GQfW9r8ZlF2r1uJvlzFv8nN3yV6d9LPokjImRTBxF8gP4C2QDLX0wF8NHdjpt7Ud9lKM0W5Q3be0Nsn9Nzj94QG+Fx7bT7SgA0lMLUyzk7OPg0xrP9kT+Rr1YmB9gSxfNl4+xk19vY5k/pS7Brz0YsUk0Tc8MtXpE61wXlsz6+VbOk2e8M6+HVtX39FNbGfhf5jHDu/k14EYtQv/g9ZRVUyQh6F9bC5Wv/g1Cs1VvoTLKq56yJQF9y3oRtx0OrX2bH2JlmBfs0aeY5rlQ==&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;md5_of_body&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;c923g2gf23g2g95asdg23sd12tg2g&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;body&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;8&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;attributes&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SenderId&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;12345&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ApproximateFirstReceiveTimestamp&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;13458591097096&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ApproximateReceiveCount&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SentTimestamp&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1758926812155&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;md5_of_message_attributes&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;message_attributes&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;EventType&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Updated&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bodyMessage&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:{&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;samplesA&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;A&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;sampleB&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;B&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;...&lt;/p&gt;

</description>
    </item>
    <item>
      <title>PostgreSQL &amp; PgAdmin using Docker + Postgres Commands</title>
      <dc:creator>Gavin Dang</dc:creator>
      <pubDate>Mon, 01 Apr 2024 03:08:50 +0000</pubDate>
      <link>https://dev.to/gavindang2911/postgresql-pgadmin-using-docker-postgres-commands-3k35</link>
      <guid>https://dev.to/gavindang2911/postgresql-pgadmin-using-docker-postgres-commands-3k35</guid>
      <description>&lt;p&gt;Ref: &lt;a href="https://migueldoctor.medium.com/how-to-run-postgresql-pgadmin-in-3-steps-using-docker-d6fe06e47ca1"&gt;https://migueldoctor.medium.com/how-to-run-postgresql-pgadmin-in-3-steps-using-docker-d6fe06e47ca1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Step1: &lt;br&gt;
Download postgres docker image&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ docker pull postgres:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step2:&lt;br&gt;
Download pgadmin4&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ docker pull dpage/pgadmin4:latest

$ docker run -p 5050:80 -e 'PGADMIN_DEFAULT_EMAIL=pgadmin4@pgadmin.org' -e 'PGADMIN_DEFAULT_PASSWORD=admin' -d --name pgadmin4 dpage/pgadmin4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step3:&lt;br&gt;
Setup pgadmin 4&lt;br&gt;
Open pgAdmin4 in your browser at: &lt;a href="http://localhost:5050"&gt;http://localhost:5050&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Log in:&lt;/p&gt;

&lt;p&gt;Username: &lt;a href="mailto:pgadmin4@pgadmin.org"&gt;pgadmin4@pgadmin.org&lt;/a&gt;&lt;br&gt;
Password: admin&lt;br&gt;
Click Add New Server and fill in the following fields:&lt;/p&gt;

&lt;p&gt;Server Name: pg (or whatever you prefer)&lt;br&gt;
On the Connection tab:&lt;br&gt;
Host: host.docker.internal&lt;br&gt;
Port: 49153&lt;br&gt;
Username: postgres&lt;br&gt;
Password: postgrespw&lt;/p&gt;



&lt;p&gt;Postgres Commands&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo service postgresql start
sudo -u postgres psql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;list of relations&lt;/em&gt;&lt;br&gt;
&lt;code&gt;postgres=# \dt&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;list of databases&lt;/em&gt;&lt;br&gt;
 &lt;code&gt;postgres=# \l&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Connect to specific database&lt;/em&gt;&lt;br&gt;
 &lt;code&gt;postgres=# \c "database name"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;List info in a table&lt;/em&gt;&lt;br&gt;
&lt;code&gt;databaseName=# \d user&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;&lt;em&gt;show data in a table&lt;/em&gt;&lt;br&gt;
&lt;code&gt;TABLE "tableNamehere";&lt;/code&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Docker Commands</title>
      <dc:creator>Gavin Dang</dc:creator>
      <pubDate>Sat, 30 Mar 2024 07:26:33 +0000</pubDate>
      <link>https://dev.to/gavindang2911/docker-32bk</link>
      <guid>https://dev.to/gavindang2911/docker-32bk</guid>
      <description>&lt;h2&gt;
  
  
  Installing docker Ubuntu
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get update
sudo apt install docker.io

sudo systemctl disable docker
sudo systemctl stop docker

sudo service docker start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Sample Dockerfile
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM node:*-alpine

# update packages
RUN apk update

# create root application folder
WORKDIR /app

# copy configs to /app folder
COPY package*.json ./
COPY tsconfig.json ./
# copy source code to /app/src folder
COPY src /app/src

# check files list
RUN ls -a

RUN npm install
RUN npm run build

EXPOSE 7777

CMD [ "node", "./dist/main.js" ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Docker commands
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Images
&lt;/h3&gt;

&lt;p&gt;Build docker image&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker build -t test-image-name .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run image in interactive mode&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -it -p 7777:7777 test-image-name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or run image in silent(daemon) mode&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -d -p 7777:7777 test-image-name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;List all images&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker image ls
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remove all images at once&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker rmi $(docker images -q)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Containers
&lt;/h3&gt;

&lt;p&gt;List all active containers&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker ps
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;List all active and dead containers&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker ps -a
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Stop all running containers&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker stop $(docker ps -a -q)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Delete all stopped containers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker rm $(docker ps -a -q)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Other
&lt;/h3&gt;

&lt;p&gt;Install help utils&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apt-get install iputils-ping nmap
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Jump into container shell&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker exec -it CONTAINER_ID /bin/sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
  </channel>
</rss>
