Sunday, July 17, 2022

Git Interview Questions

 

What is Git and why is it used?
  • Git is the most popular, open-source, widely used, and an example of distributed version control system (DVCS) used for handling the development of small and large projects in a more efficient and neat manner.
  • It is most suitable when there are multiple people working on projects as a team and is used for tracking the project changes and efficiently supports the collaboration of the development process.
  • With the help of the versioning system, the developer can identify who has made what changes and then run tests and fix bugs if any and then do necessary feature implementation. In case of any unforeseen circumstances, the code can be reverted to any of the previously working versions thereby saving huge efforts.

 GIT Cheat Sheet: Basic to Advanced Concepts

Scope of Git:
  • Due to a well-established version control system and the support for collaborative work, git has garnered wide popularity not just amongst the software developers, but also among the people who do other tasks like documentation or any other collaborative work. It can seem challenging at first, but once we get the hang of git, we find that it makes our lives much simpler.
  • It has an amazing branching system that supports nonlinear development along with keeping the developers accountable for their code. This helps in making the development process efficient and faster.

Basic GIT Interview Questions

1. What is a version control system (VCS)?

A VCS keeps track of the contributions of the developers working as a team on the projects. They maintain the history of code changes done and with project evolution, it gives an upper hand to the developers to introduce new code, fixes bugs, and run tests with confidence that their previously working copy could be restored at any moment in case things go wrong.

2. What is a git repository?

A repository is a file structure where git stores all the project-based files. Git can either stores the files on the local or the remote repository.

3. What does git clone do?

The command creates a copy (or clone) of an existing git repository. Generally, it is used to get a copy of the remote repository to the local repository.

4. What does the command git config do?

The git config command is a convenient way to set configuration options for defining the behavior of the repository, user information and preferences, git installation-based configurations, and many such things. 

For example:
To set up your name and email address before using git commands, we can run the below commands:

  • git config --global
    user.name
    “<<your_name>>”
     
  • git config --global user.email “<<your_email>>”
5. Can you explain head in terms of git and also tell the number of heads that can be present in a repository?
  • head is nothing but a reference to the last commit object of a branch.
  • For every repository, there will always be a default head referred to as “master” or now “main” (as per GitHub) but there is no restriction to the count of heads available. In other words, it can have any number of heads.
  • Usages:

    - To go or checkout to 1 commit before the latest commit, we use git checkout HEAD~1

    - To uncommit the last 3 commits without losing the changes, we first run git reset HEAD~3. Then we can see the changes made in the last 3 commits and then update it manually and commit it finally.

    - In order to uncommit the last 3 commits and also remove the changes, we can run the command: git reset --hard HEAD~3. This command will completely remove all the changes.

    - To look into the changes made in the last 3 commits, we can run git diff HEAD~3

    - To make a new commit by reverting the last 3 commits, we can run the command: git revert --no-commit HEAD~3...HEAD
6. What is a conflict?
  • Git usually handles feature merges automatically but sometimes while working in a team environment, there might be cases of conflicts such as:

    1. When two separate branches have changes to the same line in a file
    2. A file is deleted in one branch but has been modified in the other.
     
  • These conflicts have to be solved manually after discussion with the team as git will not be able to predict what and whose changes have to be given precedence.
7. What is the functionality of git ls-tree?

This command returns a tree object representation of the current repository along with the mode and the name of each item and the SHA-1 value of the blob.

8. What does git status command do?

git status command is used for showing the difference between the working directory and the index which is helpful for understanding git in-depth and also keep track of the tracked and non-tracked changes.

9. Define “Index”.

Before making commits to the changes done, the developer is given provision to format and review the files and make innovations to them. All these are done in the common area which is known as ‘Index’ or ‘Staging Area’.

In the above image, the “staged” status indicates the staging area and provides an opportunity for the people to evaluate changes before committing them.

10. What does git add command do?
  • This command adds files and changes to the index of the existing directory.
     
  • You can add all changes at once using git add . command.
     
  • You can add files one by one specifically using git add <file_name> command.
     
  • You can add contents of a particular folder by using git add /<folder_name>/ command.

Intermediate GIT Interview Questions

11. Why is it considered to be easy to work on Git?

With the help of git, developers have gained many advantages in terms of performing the development process faster and in a more efficient manner. Some of the main features of git which has made it easier to work are:

  • Branching Capabilities:

    - Due to its sophisticated branching capabilities, developers can easily work on multiple branches for the different features of the project.
    - It also has an easier merge option along with an efficient work-flow feature diagram for tracking it.
     
  • Distributed manner of development:

    - Git is a distributed system and due to this nature, it became easier to trace and locate data if it's lost from the main server.
    - In this system, the developer gets a repository file that is present on the server. Along with this file, a copy of this is also stored in the developer’s system which is called a local repository.
    - Due to this, the scalability of the project gets drastically improved.
     
  • Pull requests feature:

    - This feature helps in easier interaction amongst the developers of a team to coordinate merge-operations.
    - It keeps a proper track of the changes done by developers to the code.
     
  • Effective release cycle:

    - Due to the presence of a wide variety of features, git helps to increase the speed of the release cycle and helps to improve the project workflow in an efficient manner.
12. How will you create a git repository?
  • Have git installed in your system. 
  • Then in order to create a git repository, create a folder for the project and then run git init
  • Doing this will create a .git file in the project folder which indicates that the repository has been created.
13. Tell me something about git stash?

Git stash can be used in cases where we need to switch in between branches and at the same time not wanting to lose edits in the current branch. Running the git stash command basically pushes the current working directory state and index to the stack for future use and thereby providing a clean working directory for other tasks.

14. What is the command used to delete a branch?
  • To delete a branch we can simply use the command git branch –d [head].
  • To delete a branch locally, we can simply run the command: git branch -d <local_branch_name>
  • To delete a branch remotely, run the command: git push origin --delete <remote_branch_name>
  • Deleting a branching scenario occurs for multiple reasons. One such reason is to get rid of the feature branches once it has been merged into the development branch.
15. What differentiates between the commands git remote and git clone?

git remote command creates an entry in  git config that specifies a name for a particular URL. Whereas git clone creates a new git repository by copying an existing one located at the URL.

16. What does git stash apply command do?
  • git stash apply command is used for bringing the works back to the working directory from the stack where the changes were stashed using git stash command.
  • This helps the developers to resume their work where they had last left their work before switching to other branches.
17. Differentiate between git pull and git fetch.
git pull git fetch
This command pulls new changes from the currently working branch located in the remote central repository.This command is also used for a similar purpose but it follows a two step process: 
1. Pulls all commits and changes from desired branch and stores them in a new branch of the local repository. 
current
2. For changes to be reflected in the current / target branch, git fetch should be followed by git merge command.
git pull = git fetch + git merge
18. Can you give differences between “pull request” and “branch”?
pull requestbranch
This process is done when there is a need to put a developer’s change into another person’s code branch. A branch is nothing but a separate version of the code.
19. Why do we not call git “pull request” as “push request”?
  • “Push request” is termed so because it is done when the target repository requests us to push our changes to it.
  • “Pull request” is named as such due to the fact that the repo requests the target repository to grab (or pull) the changes from it.
20. Can you tell the difference between Git and GitHub?
GitGitHub
This is a distributed version control system installed on local machines which allow developers to keep track of commit histories and supports collaborative work.This is a cloud-based source code repository developed by using git.
This is maintained by “The Linux Foundation”.This was acquired by “Microsoft”
SVN, Mercurial, etc are the competitorsGitLab, Atlassian BitBucket, etc are the competitors.
  • GitHub provides a variety of services like forking, user management, etc along with providing a central repository for collaborative work.
21. What do the git diff and git status commands do?
git diffgit status
This shows the changes between commits, working trees, etc.This shows the difference between the working directory and index that is essential in understanding git in depth.
  • git diff works in a similar fashion to git status with the only difference of showing the differences between commits and also between the working directory and index.
22. What has to be run to squash multiple commits (last N) into a single commit?

Squashing multiple commits to a single one overwrites the history which is why it is recommended to be done using full caution. This step can be done by running the command: git rebase -i HEAD~{{N}} where {{N}} represents the number of commits needed to be squashed.

23. How would you recover a branch that has already pushed changes in the central repository but has been accidentally deleted from every team member’s local machines?

We can recover this by checking out the latest commit of this branch in the reflog and then checking it out as a new branch.

24. Can you tell something about git reflog?

This command tracks every single change made in the repository references (that can be branches or tags) and also maintains the branches/tags log history that was either created locally or checked out. Reference logs such as the commit snapshot of when the branch was created or cloned, checked-out, renamed, or any commits made on the branch are maintained by Git and listed by the ‘reflog’ command.

  • This recovery of the branch is only possible when the branch was either created locally or checked-out from a remote repository in your local repository for Git to store its reference history logs.
  • This command should be executed in the repository that had the lost branch.
25. What consists of a commit object?

A commit object consists of the following components:

  • A set of files that represents the state of a project at a given point in time.
  • Reference to parent commit objects.
  • A 40 character string termed as SHA-1 name uniquely identifies the commit object.
26. Explain the levels in git config and how can you configure values using them?
  • In order to make git work, it uses a set of configurations that are pre-defined by default by means of configuration files (or config files). We can change the default behavior of git by just modifying these files which are basically text files. In order to do this, it is important to understand how git identifies these files. It does so by following the below steps:

    - Firstly, git searches for the config values in the system-wide gitconfig file stored in <<installation_path>>/etc/gitconfig file that has settings defined and applied to every user of the system and all their repos.
         - In case you want git to search from this particular file and read/write on it, we can pass the option --system to git config command.

    - Next, git searches for the ~/.gitconfig file or ~/.config/git/config that has the scope specific to the user.
       - Git can be made to read/ write from this file specifically bypassing --global to the git config command.

    - Lastly, git searches for the config values in the git directory of the local repository that we are currently working on.
       - These config values are specific to that particular repository alone and can be accessed by passing --local to the git config command.This is the default config file that gets accessed and modified upon in case we do not specify any levels.
27. What is a detached HEAD and what causes this and how to avoid this?

Detached HEAD indicates that the currently checked-out repository is not a local branch. This can be caused by the following scenarios:

  • When a branch is a read-only branch and we try to create a commit to that branch, then the commits can be termed as “free-floating” commits not connected to any branch. They would be in a detached state.
  • When we checkout a tag or a specific commit and then we try to perform a new commit, then again the commits would not be connected to any branch. When we now try to checkout a branch, these new commits would be automatically placed at the top.

    In order to ensure that detached state doesn't happen, =instead of checking out commit/tag, we can create a branch emanating from that commit and then we can switch to that newly created branch by using the command: git checkout -b <<new_branch_name>>. This ensures that a new branch is checkout out and not a commit/tag thereby ensuring that a detached state wouldn't happen.
28. What does git annotate command do?
  • This command annotates each line within the given file with information from the commit which introduced that change. This command can also optionally annotate from a given revision.
  • Syntax: git annotate [<options>] <file> [<revision>]
  • You can get to learn more about this command from the official git documentation here.
29. What is the difference between git stash apply vs git stash pop command?
  • git stash pop command throws away the specified stash (topmost stash by default) after applying it.
  • git stash apply command leaves the stash in the stash list for future reuse. In case we wanted to remove it from the list, we can use the git stash drop command.
git stash pop = git stash apply + git stash drop

Advanced GIT Interview Questions

30. What command helps us know the list of branches merged to master?
  • git branch --merged helps to get the list of the branches that have been merged into the current branch.
  • Note: git branch --no-merged lists the branches that have not been merged to the current branch.
31. How will you resolve conflict in Git?
  • Conflicts occur whenever there are multiple people working on the same file across multiple branches. In such cases, git won't be able to resolve it automatically as it is not capable of deciding what changes has to get the precedence.
  • Following are the steps are done in order to resolve git conflicts:
    1. Identify the files that have conflicts.
    2. Discuss with members who have worked on the file and ensure that the required changes are done in the file.
    3. Add these files to the staged section by using the git add command.
    4. Commit these changes using the git commit command.
    5. Finally, push the changes to the branch using the git.
32. What is best advisable step in cases of broken commit: Create an additional commit OR amend an existing commit?
  • It is always advisable to create an additional commit rather than amending the existing commit due to the following reasons:
    - Doing the amend operation destroys the previously saved state of that commit. If only the commit message gets changes or destroyed, it's acceptable but there might be cases when the contents of the commits get amended. This results in the loss of important information associated with the commit.
    - Over usage of git commit --amend can have severe repercussions as the small commit amend can continue to grow and gather unrelated changes over time.
33. How to revert a bad commit which is already pushed?

There can be cases where we want to revert from the pushed changes and go back to the previous version. To handle this, there are two possible approaches based on the situations:

  • Approach 1: Fix the bad changes of the files and create a new commit and push to the remote repository. This step is the simplest and most recommended approach to fix bad changes. You can use the command: git commit -m "<message>"
  • Approach 2: New commit can be created that reverts changes done in the bad commit. It can be done using git revert <name of bad commit>
34. What is the functionality of “git cherry-pick” command?

This command is used to introduce certain commits from one branch onto another branch within the repository. The most common use case is when we want to forward- or back-port commits from the maintenance branch to the development branch.

35. Explain steps involved in removing a file from git index without removing from the local file system?
  • Sometimes we end up having certain files that are not needed in the git index when we are not being careful while using the git add command. Using the command git rm will remove the file from both the index and the local working tree which is not always desirable.
     
  • Instead of using the git rm command we can use the git reset command for removing the file from the staged version and then adding that file to the .gitignore file to avoid repeating the same mistake again.
git reset <file_name> # remove file from index
echo filename >> .gitingore  # add file to .gitignore to avoid mistake repetition.
36. What are the factors involved in considering which command to choose among: git merge and git rebase?

Both these commands ensure that changes from one branch are integrated into another branch but in very different ways. Git rebasing can be thought of as saying to use another branch as a new base for the work.

  • Whenever in doubt, it is always preferred to use the git merge command.

    Following are some factors that tell when to use merge and rebase commands:
     
  • In case our branch gets contributions from other developers outside the team as in open-source or public repositories, then rebase is not preferred.
    - This is because rebase destroys the branch and it results in broken and inconsistent repositories unless the git pull --rebase command is used.
  • Rebase is a very destructive operation. If not applied correctly, it results in loss of committed work which might result in breaking the consistency of other developer’s contribution to the repository.
  • If the model of having branches per feature is followed, rebasing is not a good idea there because it keeps track of related commits done by the developers. But in case the team follows having branches per developer of the team, then the branch has no additional useful information to be conveyed. In this model, rebasing has no harm and can be used.
  • If there is any chance where there might be a necessity to revert a commit to previous commits, then reverting a rebase would be almost impossible as the commit data would be destroyed. In such cases, the merge can be used.
37. How do you find a commit which broke something after a merge operation?
  • This can be a time-consuming process if we are not sure what to look at exactly. Fortunately, git provides a great search facility that works on the principle of binary search as git-bisect command.
  • The initial set up is as follows:
 git bisect start         # initiates bisecting session
git bisect bad           # marks current revision as bad
git bisect good revision # marks last known commit as good revision
  • Upon running the above commands, git checks out a revision that is labeled as halfway between “good” and “bad” versions. This step can be run again by marking the commit as “good” or “bad” and the process continues until the commit which has a bug is found.
38. What are the functionalities of git reset --mixed and git merge --abort?
  • git reset --mixed command is used for undoing changes of the working directory and the git index.
  • git merge --abort command is used for stopping the merge process and returning back to the state before the merging occurred.
39. Can you tell the differences between git revert and git reset?
git revert git reset
This command is used for creating a new commit that undoes the changes of the previous commit.This command is used for undoing the local changes done in the git repository
Using this command adds a new history to the project without modifying the existing historyThis command operates on the commit history, git index, and the working directory.
40. Mention the most commonly used Git commands and their functions. 

Your interviewer can ask you about the following commands individually, or you may have to draw comparisons between them. You must prepare this crucial Git interview question thoroughly. The following table enumerates some key commands and their functions:

Git Commands and Functions

git config: It configures the username and email address.

git add: This command adds one or more files to the staging area.

git add <file_name>: It specifically adds files one by one.

git init: This command initializes an empty Git repository.

git commit: It allows you to commit changes to the head but not to the remote repository.

git stash: It provides a clean working directory for other tasks while pushing the current working directory state and index to the stack for future use.

git stash drop: It deletes the stashed element (last-added stash item by default)  from the directory. Can also delete a specific topic included as an argument.

git stash pop: It discards the specified stash (topmost stash by default) after applying it.

git pull: It pulls innovation or commits from a specific branch of your central repository. It also updates your object branch in your local repository.

git fetch: It pulls all new commits from the desired branch. It then saves it in a new branch in your local repository.

git merge: It reflects the git fetch changes in your target branch. You can use git merge and specify the name of the other branch to bring it into the target branch.

git branch - merged: This command records the branches merged into the present branch.

git reset --mixed: You can use it for undoing changes of the working directory and the git index.

git merge --abort: It stops the merge process and returns back to the state before the merging occurs.

git revert: It creates a new commit to undo the changes of the previous commit. This command adds a new history without modifying the existing one.

git reset: You can use this command for undoing the local changes done in the git repository. It operates on the git index, commit history, and the working directory.

git status: It shows the difference between the working directory and the index.   

git clone: It generates a copy of a current Git repository.

git remote: It helps you create, view, and delete remotes associated with the local repository.

git branch –d [head]: It simply deletes a branch.

git branch -d <local_branch_name>: You can use this command to delete a branch locally.

git push origin --delete <remote_branch_name>: You can use this command to delete a branch remotely.

git reflog: It tracks every single change made in the repository references and maintains the branches/tags log history, and thus gets the name reflog (reference + log).

git annotate [<options>] <file> [<revision>]: It annotates each line with information from the commit which introduced that change. It can also optionally annotate from a given revision.

git cherry pick: It introduces certain commits from one branch into another branch within the repository. 

git bisect: It performs a binary search and detects the commit that introduced a bug or regression in the project’s history.

Redis Interview Questions

Q: What is Redis?
Ans:

Redis is a distributed in-memory key-value database, cache, and message broker with optional durability. Redis supports different kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indexes.

Q: What is the meaning of Redis?
Ans:

Redis stands for REmote DIctionary Server.

Q: What is in-memory Database
Ans:

A database that holds the dataset in RAM is known as an in-memory database. This means that if you communicate with a database, you can only use Main memory; no DISK operations will be performed. As a result, the process will be quicker since it will access the main memory directly rather than using the disc.

Q: What is Redis Replication?
Ans:

Redis uses non-blocking asynchronous replication, with asynchronous replica-to-master acknowledges of the amount of data processed. A master can have multiple replicas. It ensures that the master will continue to handle queries when one or more replicas perform the initial synchronization or a partial resynchronization. Replication is also largely non-blocking on the replica side.

Q: What is Spring Session Data Redis?
Ans:

Spring provides session repository for Redis database session management. In Spring Boot, we can make use of HTTPSession with Spring Session Data Redis to store the session data in persistent storage (Redis).

Refer for implementation of Spring Boot Session Management using Redis

Q: Why Redis is fast?
Ans:

Redis is a data structure server. As a key-value data store, Redis is same as Memcached, but it has two major advantages over, support of additional datatypes and persistence. Since all of the data is stored in RAM, because of that system speed become extremely quick, sometimes perform even better that Memcached.

Q: Why is Redis faster than SQL?
Ans:

Since Redis stores data in primary memory, because of that Read and Write operations will be extremely fast.

In RDBMS, Read and Write operations are slow because it stores data in secondary memory.

Primary memory is in lesser in size and much expensive than secondary so, Redis cannot store large files or binary data.

Q: What are differences between Redis and RDBMS?
Ans:

Redis

RDBMS

Redis stores everything in primary memory.

RDBMS stores everything in secondary memory.

In Redis, it stores data in primary memory because of that Read and Write operations are extremely fast.

In RDBMS, it stores data in secondary memory and because of that Read and Write operations are slow.

Since primary memory is smaller and more costly than secondary memory, Redis is unable to store large files or binary data.

Since secondary memory is larger and less expensive than primary memory, RDBMS can easily handle these types of files and data.

Redis is only used to store small quantities of textual data that must be accessed, updated, and added quickly. You'll get errors if you try to write bulk data that exceeds the available memory.

RDBMS can store large amounts of data that aren't used regularly and aren't needed to be fast.

 

Q: How to install Redis?
Ans:

Follow the steps given here to install Redis Client/Server.

Q: What is the maximum size of key (String) in redis?
Ans:

According to the redis official docs, the maximum size of key in redis is 512MB.

Q: How many data types are there in Redis?
Ans:

Redis provide 5 types of data types. Strings, Hashes, Lists, Sets, Sorted Sets

Q: Can we store JSON in Redis?
Ans:

JSON can be stored in redis as a plain string in a separate key (or as a member/value of a set/list) or as a hash structure.

 


Rabbitmq Interview Questions


Q: What is RabbitMQ?
Ans:

RabbitMQ is an open-source message-broker software is also known as message queueing technology. It defines queues to which applications communicate for data transfer, or message transmission. Any kind of information could be included in a message. This message is processed by the recipient application.


Q: How RabbitMQ works, and it's Standard message flow?
Ans:

An exchange must accept messages from the supplier request and route them to message queues using header attributes, bindings and routing keys. A binding is set up to connect the queue to an exchange.



As shown above in screen shot, below are the Standard message flow.
1) The producer publishes a message to an exchange. When you create the exchange, you have to specify the type of it. The different types of exchanges are explained in detail later on.
2) The exchange receives the message and is now responsible for the routing of the message. The exchange takes different message attributes into account, such as routing key, depending on the exchange type.
3) Bindings have to be created from the exchange to queues. In this case, we see two bindings to two different queues from the exchange. The Exchange routes the message into the queues depending on message attributes.
4) The messages stay in the queue until they are handled by a consumer
5) The consumer handles the message.

 

Q: When and why to use RabbitMQ?
Ans:

Message queueing is useful when you want to exchange a message for consumption or for balance of loads between workers with multiple recipients. The user is able to take a message from the queue while the producer is in the queue, and start processing. The consumer can be on a different server or on the same server than the publisher. The requested application can be of one language and the consumer application is of other language - the message broker would not care about the application languages, it just send messages between consumer and reciever. Which also reduces the dependencies or coupling between the application.

Q: What Is binding And routing Key?
Ans:

A binding is a "bridge" that you set up to connect a queue to an exchange.
The routing key is an attribute message that the exchange examines when determining how to route the message to queues.

Q: What is a RabbitMQ channel?
Ans:

They enable you to have a single connection to the RabbiMQ server, but for different parts of your application they have sandboxed communication. Channels are how the RabbitMQ server communicates with your application. It hold one connection (instance) per client process and many channels in that process (instance)


Q: What is a dead letter queue in rabbitmq?
Ans:

In general, a death letter queue (DLQ), also referred to as an undelivered-message queue, is a holding queue of messages that can not be sent to their destinations for some reason.
In rabbitmq, the dead letter queue is service implementation to store messages that satisfy one or more of the following failure criteria.

  • Message that is sent to a queue that does not exist.
  • Queue length limit exceeded.
  • Message length limit exceeded.
  • Message is rejected by another queue exchange.
  • Message reaches a threshold read counter number, because it is not consumed. Sometimes this is called a "back out queue".



Q: How to implement RabbitMQ retry mechanism?
Ans:

Whenever any data in the message is transmitted that the receiver does not accept, or when a message is sent to a queue that does not exist. The message is retried and sent up to a set number of times. Even if the communication is not received by the recipient but is sent from the sender's end. Now In such instances, the message queue is marked as undeliverable or deadLetter queue.

            RabbitMQ provides a method for handling message failures in a really 

            efficient way known as the Retry and Error Handling feature.

Refer Spring Boot + RabbitMQ + Retry Error Handling Example

Q: How to install and configure RabbitMQ at local?
Ans:

Refer Setup RabbitMQ at Local
OR
Refer Install RabbitMQ using Docker




Q: What is Exchange?
Ans:

Messages are not posted directly in the queue; rather, the user sends messages to the exchange. An exchange is responsible for routing the messages to the various queues. An exchange receives messages from the producer request and routes them by bindings and routing keys to message queues. A binding is a linkage between an exchange and a queue.

 

Q: Types of Exchange?
Ans:















Direct: Direct exchange transfers messages to queues on the basis of a message routing key. The message is routed in a direct exchange to the queues whose binding key exactly matches the message's routing key. If the queue is bound to the binding key exchange, a message will be sent to the exchange with a routing key to the queue.
Fanout: A fanout sends messages to all the queues linked to it.
Topic: The topic exchange matches the wildcard between the routing key and the binding routing pattern.
Headers: Headers exchanges use the routing attributes of the message header.


Q: Which Protocol RabbitMQ uses?
Ans:

RabbitMQ uses Advanced Message Queuing Protocol (AMQP). Its an open standard layer used to communicates date across network by means of byte stream.

Q: What is RabbitMQ Vhost?
Ans:

Virtual Host (a.k.a. ' vhost ') in AMQP is a namespace for objects such as Exchanges, Queues and Bindings. RabbitMQ utilizes more concrete implementation of virtual hosts, through effectively making them "virtual clusters" on top of the broker.


Q: How RabbitMQ differs from ActiveMQ?
Ans:

RabbitMQ is open source message broker with support for several protocols, written in Erlang. Whereas ActiveMQ is also open source with support for several protocols, written in Java langauge.


Q: Is RabbitMQ support MQTT (Message Queue Telemetry Transport)?
Ans:

RabbitMQ supports MQTT 3.1.1 through a plugin that ships to the core distribution.
Supported MQTT Features:

  • QoS0 and QoS1 publish & consume
  • QoS2 publish (downgraded to QoS1)
  • TLS
  • Session stickiness
  • Retained messages with pluggable storage backends
  • Last Will and Testament (LWT)
Q: Is RabbitMQ persistent?
Ans:

Having a queue durable is not same as making persistent messages. Messages can be distributed either with making mode to persistent or transient. When you post your message, you need to set the delivery mode to persistent if you want it to remain in your long-lasting queue during restart.


Q: Is RabbitMQ uses database?
Ans:

RabbitMQ intentionally does not store messages in a database. RabbitMQ writes messages to disk in below two ways:

  • Messages published in delivery_mode=2
  • Memory pressure causes RabbitMQ to run out of RAM and transfers messages to the disk to free up RAM.
Q: Does RabbitMQ is PUSH or PULL?
Ans:

RabbitMQ uses a PUSH template and prevents exhausting consumers through the prefetch configured limit. PULL is used by Kafka, where consumers request for messages from a particular offset batches.


Q: What is Dead Letter Exchange in Rabbitmq?
Ans:

If there is no appropriate queue for the message, the message will be dropped quietly. RabbitMQ offers an AMQP extension known as the "Dead Letter Exchange". The dead letter exchange provides features for collecting non-deliverable messages.


Q: What is pub sub, how it works?
Ans:

pub/sub messaging is a asynchronous service-to-service communication, it's a two way communication.
Mainly used in statelss, microservices. In this type of model, once message published to a topic, it gets received immediately by all subscriber to the topic.


Q: Is RabbitMQ an ESB?
Ans:

RabbitMQ is a messaging broker, whereas Mule is an ESB (Enterprise Service Bus). An ESB includes additional layers on top of a message broker like routing, transformations and business process management


Q: Which design patterns RabbitMQ uses.
Ans:

As a strong messaging model transmitting messages among endpoints in the communication channel has many features / uses. It uses asynchronous architectural patterns to decouple applications.


Q: How to monitor rabbitMQ queue.
Ans:

Monitoring is a process of capturing behaviour of your application using health checks and metrics.
There are many tools available to monitors the application like AppDynamics,DataDog,AWS CloudWatch etc.


Q: What is Synchronous and Asychronous messaging.
Ans:

Synchronous messaging is a two way communication, where sender sends a message to receiver and receiver receives message and gives reply to the sender. Where as Asynchronous Messaging is a communication where a message is placed in a message queue and does not require an immediate response from receiver.


Q: Which Messaging patterns are getting used in RabbitMq?
Ans:

Messaging patterns are implemented in RabbitMQ on the basis of exchanges queues and bindings. We may distinguish between the different approaches to implementing a RabbitMQ design pattern: point-to-point communication publish-subscribe request-response communication

 

Q: What is Point to Point Communication?
Ans:

Point-to-point connection is a communications connection between two communication endpoints/nodes.


Q: How RabbitMQ differs from Kafka?
Ans:

RabbitMQ is a lightweight message broker used to communicates messages between consumer and producer and it supports many protocols like AMQP, MQTT,STOMP. Whereas Kafka manages large amounts of data with very little overhead-Kafka was designed for large volumes of messages to be stored and distributed.
Refer Apache Kafka Tutorial to understand Kafka with example.


Q: What is Pub Sub Communication?
Ans:

Pub / sub messaging is a two-way communication between asynchronous user and service., mainly used in stateless microservices.


Q: What is Request-Response communication?
Ans:

Request–Response, or Request–Reply,is strong messaging patterns where requester send message to a replier, and in return replier send response back to replier.


Q: What is Erlang RabbitMQ?
Ans:

The RabbitMQ server software is written in the programming language of Erlang and is based on the clustering and failover architecture of the Open Telecom Framework.

 

Q: Is RabbitMQ support message priority queues?
Ans:

To make the queue function as a priority queue, provide an x-max-priority property when the queue is established.
x-max-priority declares the maximum priority number in the queue.
In JavAns: Set priority as given below:

Map<String, Object> queuePriorityProp = new HashMap<>();
queuePriorityProp.put("x-max-priority", 10); // max priority is 10
channel.queueDeclare(QUEUE_NAME, durable, false, false, queuePriorityProp);

Publish messages of a particular priority,

String queueNote = "Set note priority 8";
AMQP.BasicProperties.Builder queueProps = new AMQP.BasicProperties.Builder();
queueProps.contentType("text/plain")
            .priority(8);
channel.basicPublish("", QUEUE_NAME, queueProps.build(), queueNote.getBytes());