Image for post
Image for post

Because libraries solve some problems in a specific area and allow making something easier, we use tons of libraries/frameworks and internal project components written by us… in order to make an application easier. However, this situation brings other complexities that we need to take care of, like relations between the components. In this article, I would like to mention how to use the technique as known as Dependency Injection in a TypeScript project.

What Is Dependency Injection?


Image for post
Image for post

As you know, Github allows us to execute continuous integration pipelines through Actions easily. Today, we are going to see how to deploy your code directly from Github to your server by using Ansible, Docker, and Github Actions.

What Is Challenge Here?

Ansible is an IT automation tool that communicates to servers via SSH protocol without using any agent mechanism. It allows you to execute commands on remote servers or transferring files to servers from the system where you run the Ansible playbook. So the key problem is being able to access the remote servers from a public system like Github.

How To Solve?

We can execute the Ansible playbooks in a docker container through Github Actions by using a specific private key that eligible to access the remote servers. …


Image for post
Image for post

In a development environment, one of the biggest problems is finding the occurred problem between the services and it needs that you need to check too many log files in order to find the root cause. You may need to check the web, application, database, cache… etc. server logs even in a simple monolith application.

Today, we’ll see how to aggregate the application logs in one single place that we can follow easily through Docker Compose, Graylog, and Elasticsearch.

Dockerizing The Application

As a sample application, I’ve chosen Symfony Demo project written in PHP. It requires PHP, Nginx and MYSQL instances to work. Since we need some customization on PHP-PFM and Nginx configurations, we’ll create separate custom Dockerfile(s) for both services. …


Image for post
Image for post

You may have an application that depends on one or more services that start slowly. So, you must put some extra controls before starting the application, in order to prevent startup errors and run the application smoothly.

Let’s take the following example:

We have an application that directly dependent on RabbitMQ and MySQL services and it connects to both services in application startup. However, the worker container constantly fails because it starts before the other services.

Let’s start first by defining the dependencies between the services in the docker-compose.yaml to start the worker container after RabbitMQ and MySQL containers.


Image for post
Image for post

Sometimes, a message consumer might be failed because of connection issues or other logical reasons. In this case, the application should handle the fail scenario properly and retry the failed message several times based on some rules.

Today, we are gonna see how to retry a failed message in a Symfony application through Messenger Component by referencing the previous post:

https://medium.com/@ibrahimgunduz34/using-rabbitmq-in-a-symfony-application-through-messenger-component-e61498b668b

How To Retry

Messenger Component, retries a failed message through the dead letter feature of RabbitMQ in case of RabbitMQ usage. It tries by default 3 times, with 1000 ms delay, and multiplies the duration by 2 in each try.


Image for post
Image for post

Most of the API’s requires some authentication mechanisms in order to identify the user and allows to access some resources based on the authorization rules. Although the way of the identity declaration changes, most of the authentication mechanisms requires to perform a request to an authentication endpoint in order to obtain an identifier before going to the actual resource. However, you can’t use that identifier forever.

If you take all this information into consideration, to make even a simple API call requires the following flow:


Image for post
Image for post

As you know, message-based asynchronous flows are a significant part of the web applications that allow scaling backend processes. You can move all the long time processes to asynchronous flow and make your user interface faster as much as you could.

Today, we’re gonna see how to use RabbitMQ with Symfony through Messenger component with a simple use case.
I strongly recommend to check out the following document in order to understand the message bus concept and the fundamentals of each component in Messenger:


Image for post
Image for post

The business needs changes and sometimes even you might not reach the people’s speed. No matter how reusable code that you’ve written; all your changes may become garbage in a few days with new business needs. Until MariaBundle.


Image for post
Image for post

The Bundle mechanism is a way to make reusable software packages for the PHP applications that use Symfony. It’s probable that a bundle can have own dependencies and needs to be tracking under separate version control. Although Symfony bundles are independent packages, you might still need some application dependencies during the development period in order to check the integrity or simply run the code, besides the tests. So, in this article, I’m gonna try to explain step by step, how to prepare an efficient development environment in order to develop a Symfony bundle.

1. Prepare A Docker Image

Docker is the tool that gonna help us to run the code for a specific PHP version. So, let’s start by creating a new Dockerfile with the following content. …


Image for post
Image for post

As you know, aws-sdk-mock is an awesome library that allows you to mock aws service calls in the tests. However, you can’t mock the service instances by aws-sdk-mock in some cases like if you instantiated the instances in the global scope and trying to mock/restore before/after each test cases. Today we will try to find a way to mock and restore the service instances by using jest and aws-sdk-mock in order to write a proper test.

Before starting, there two things you need to know;

  • The first one is you can’t mock and restore service instances in beforeEach() and afterEach() methods as long as they are instantiated in the global scope. …

About

İbrahim Gündüz

My Personal Blog

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store