Showing posts with label developer. Show all posts
Showing posts with label developer. Show all posts

Wednesday, July 26, 2023

Rabbit Message Queue and Redis

 In this article I will try to give some overview about why and when to use Rabbit Message Queue and Redis cache. Starting with Redis cache

Redis cache -

  • Mainly used for caching as call time to server ( say database server ) can delay. Using redis cache saves this time, as it is the cache of the database itself.
    • Whenever a database write has happened, a worker class can update the cache to be in sync with the database.
  • Key value pair type of database supporting strings, int, lists, hash as values.
  • The list can used as stacks or queues and other data structures as well like linked list,  circular queue and all.
  • Remember, the key has to be in lower case.
  • Redis say instead of sending many continuous updates in subsequent calls, these can be piped and send as a single call.
  • Calls can be direct or pub - sub type
  • StackExchange.Redis is a popular nuget package to perform almost all the database operations in the redis documentation.
  • redis - cli can be used locally to connect to the database and perform CRUD operations.
  • Convenience of using regex in calls to retrieve data fastly.

 

Rabbit Message Queue ( RMQ ) -

  • Queue or many queues behind an exchange.
  • The exchange does the routing to the particular queue based on the header information.
  • Data in a queue can be set to be durable, meaning data is not lost after RMQ is re started. For docker containers make sure to use common volumes across container restart(s).
  • Data in a durable queue can stay from two to three days.
  • MassTransit is one nuget package which can be used with different types of Enterprise service bus like RMQ, Azure queue, AWS queue, in memory queue and all without needing to write the adapters for each.
  • When a message is sent to a RMQ it first goes to the exchange and the exchange routes that message to its queue.
  • Used mainly for mass data transfers and Mass transit client consumes it almost in no time.
  • The main reason to use Enterprise service bus is to ensure reliability of the message sent. The recipient server may be busy with some operation(s) unable to provide cycles or bandwidth to consume the incoming messages from the client. These messages can be lost if not addressed in a timely manner, thereby giving poor experience to its caller.
  • Supports direct messaging to the recipient or publish subscriber mechanism where the Consumer is listening to the queue(s) in the RMQ for any new messages.

 

Writing Consumer in Mass transit should be as straight forward as implementing the `IConsumer` type and having a task named Consume with ConsumerContext parameter like below.


    public class AfceConsumer :
        IConsumer<AfceMessage>
    {

        public Task Consume(ConsumeContext context)
        {
            Console.WriteLine("Hello {name}", context.Message.Title);
            return Task.CompletedTask;
        }
    }
The above consumer will continuously consume each message one by one in almost no time when the message of type `AfceMessage` is available in the queue.
The AfceMessage can be any reference type like a class or a record or a struct.

Mass transit also has bulk message consumer to consume message in batches.

Wednesday, July 12, 2017

Are you technically apt - Software developer

You don't have to be technically apt to be able to achieve business needs or requirements. Often in interviews people try to test your coding knowledge to the point of knowing the perfect syntax. What would happen if you actually made coding mistakes when coding on a machine, you would actually see some interpreter or compiler warnings or errors. Now can't you fix this code now. Do interviewers question this? Actually Google is just a click away to precisely help to fix issues if in case we did not understand how to fix it. Are interviewers thinking that you are a compiler or an interpreter 😀 . A knowledgeable coder is one who can pick the best method or approach for a problem rather than one who knows everything like a poem and is not good in knowing the best solution. I often find that interviewers are trying to find the later ones for their teams. Did you just read poem, yes that's correct. I was one of the worst in memorizing poems in my class and that's why I moved to  Science. I always think Science is learning based on understanding. So should the other IT people be too, if not I am afraid of its future. I am ready to take a bet on it. Having almost learnt so many programming languages I have to admit that most was possible because the boss gave me an opportunity to do it rather than question me before giving it. Yes I had some very good considerate bosses in my career. In turn I did what was expected and won accolades too like the best performer award in the government project. I always never want to work for anyone who can't praise your success or even understand it and so should anyone. Eventually people will judge you based on rumors and it has never worked in your favor.


Browser background color or monitor brightness

Have you been in a situation where you are almost sitting the whole day in front of your browser and going through a document and find that ...