Sunday, August 22, 2021

Strategy_Pattern

 namespace WindowsFormsApp

{

    public interface IEmployeeSal

    {

         float GetSalary(int basic,float dividend,float commission);

    }

}

namespace WindowsFormsApp

{

    public class HRDeptSalary : IEmployeeSal

    {

       // @Override 

        public float GetSalary(int basic, float dividend, float commission)

        {

            return basic + dividend+commission;

        }

    }

    public class SalesDept : IEmployeeSal

    {

        // @Override 

        public float GetSalary(int basic, float dividend, float commission)

        {

            return basic + dividend+commission;

        }

    }

    public class PurchaseDept : IEmployeeSal

    {

        // @Override 

        public float GetSalary(int basic, float dividend, float commission)

        {

            return basic + dividend;

        }

    }

}

namespace WindowsFormsApp

{

    public class EmployeeSalary

    {

        public string EmployeeName { get; set; }

        public int Basic { get; set; }


        private IEmployeeSal _iEmployeeSal;


        public EmployeeSalary(IEmployeeSal iEmployeeSal)

        {

            this._iEmployeeSal = iEmployeeSal;

        }


        public float CalculateSalry(int basic, float dividend, float commission)

        {

            return _iEmployeeSal.GetSalary( basic,  dividend,  commission);

        }

    }

}

private void button1_Click(object sender, EventArgs e)

        {

            //Use the EmployeeSalary to see change in behaviour when it changes its Strategy.

            EmployeeSalary objEmpSal = null;

            objEmpSal = new EmployeeSalary(new HRDeptSalary());


           textBox1.Text = objEmpSal.CalculateSalry(9000,500,50).ToString();

            objEmpSal = new EmployeeSalary(new PurchaseDept());


            textBox2.Text = objEmpSal.CalculateSalry(5000, 200, 20).ToString();


        }

Saturday, January 30, 2021

microservices

 

What are microservices?

Microservices - also known as the microservice architecture - is an architectural style that structures an application as a collection of services that are

  • Highly maintainable and testable
  • Loosely coupled
  • Independently deployable
  • Organized around business capabilities
  • Owned by a small team
The microservice architecture enables the rapid, frequent and reliable delivery of large, complex applications. It also enables an organization to evolve its technology stack.

Microservices break down the application into smaller, independent services. Each service (e.g., Catalog API, Basket API) is dedicated to a specific function and can be scaled or updated independently. It connects with databases like MongoDB, Redis, and MySQL, and uses messaging tools like RabbitMQ to stay efficient.












Installing on Windowshttps://www.rabbitmq.com/install-windows.html 




Stop then start
C:\Program Files\RabbitMQ Server\rabbitmq_server-3.12.11\sbin>
rabbitmq-plugins.bat list
C:\Program Files\RabbitMQ Server\rabbitmq_server-3.12.11\sbin>rabbitmq-plugins.bat enable rabbitmq_management




















MSMQ:
If you want to check the message queue paths directly from Windows without using code, you can also: 1. Open **Computer Management** (right-click on "This PC" or "My Computer" and select "Manage"). 2. Navigate to **Services and Applications** > **Message Queuing** to see the list of available queues.






কিভাবে কাজ করে (Bangla)

RabbitMQ-এর কাজের ধাপগুলো সহজভাবে নিচে দেওয়া হলো:

  1. Producer

    • Producer হলো সেই অ্যাপ্লিকেশন যা বার্তা (message) তৈরি করে এবং RabbitMQ-তে পাঠায়।
    • Producer বার্তাটি একটি Queue-তে পাঠায়।
  2. Queue

    • Queue হলো একটি বাফার যেখানে বার্তাগুলো জমা থাকে যতক্ষণ না Consumer সেগুলো গ্রহণ করে।
    • এটি বার্তাগুলোকে অস্থায়ীভাবে ধরে রাখে।
  3. Consumer

    • Consumer হলো সেই অ্যাপ্লিকেশন যা Queue থেকে বার্তা গ্রহণ করে এবং প্রসেস করে।
    • Consumer বার্তা পাওয়ার পর সেটি প্রিন্ট করতে পারে, ডাটাবেসে রাখতে পারে, বা অন্য কোনো কাজ করতে পারে।
  4. Connection এবং Channel

    • Producer এবং Consumer RabbitMQ সার্ভারের সাথে Connection তৈরি করে।
    • Connection-এর ভিতরে Channel থাকে, যা আসল কাজ করে (Queue declare, message publish, consume)।
  5. Flow

    • Producer → Queue → Consumer
    • Producer বার্তা পাঠায় → Queue বার্তাটি ধরে রাখে → Consumer বার্তাটি পড়ে এবং প্রসেস করে।

RabbitMQ-এর মূল সুবিধা:

  • Decoupling: Sender এবং Receiver একসাথে চলতে হবে না।
  • Reliability: বার্তা হারিয়ে যায় না (acknowledgment এবং persistence সাপোর্ট করে)।
  • Scalability: অনেক বেশি লোড হ্যান্ডেল করতে পারে।
Azure Service Bus Interview50+ Azure Service Bus Interview Q&A (Bangla + English)
Copilot said:
Copilot

Here you go, Mohammad!
50+ Azure Service Bus Interview Questions and Answers (Bangla + English) — simple, clear, side‑by‑side.
Perfect for interviews and revision.


✅ Azure Service Bus Interview – 50+ Questions & Answers

(Bangla + English side-by-side)


1. What is Azure Service Bus?

EN: Azure Service Bus is a fully managed enterprise message broker that enables reliable communication between applications using queues and topics.
BN: Azure Service Bus হলো একটি fully managed enterprise message broker, যা queues এবং topics ব্যবহার করে অ্যাপ্লিকেশনগুলোর মধ্যে নির্ভরযোগ্য যোগাযোগ নিশ্চিত করে।


2. Why do we use Azure Service Bus?

EN: It decouples systems, supports asynchronous communication, ensures reliability, and handles spikes in traffic.
BN: এটি সিস্টেমগুলোকে decouple করে, asynchronous যোগাযোগ সাপোর্ট করে, নির্ভরযোগ্যতা নিশ্চিত করে এবং হঠাৎ লোড বৃদ্ধি ম্যানেজ করে।


3. What are the key components of Service Bus?

EN: Namespace, Queues, Topics, Subscriptions, Filters, SAS Policies.
BN: Namespace, Queue, Topic, Subscription, Filter, SAS Policy।


4. What is a Service Bus Queue?

EN: A point‑to‑point messaging system (sender → queue → receiver).
BN: একটি point‑to‑point মেসেজিং সিস্টেম (sender → queue → receiver)।


5. What is a Topic?

EN: A publish‑subscribe messaging system where multiple receivers can subscribe.
BN: Publish‑subscribe মডেল যেখানে একাধিক subscriber মেসেজ পায়।


6. Difference between Queue and Topic?

EN: Queue = Single Consumer.
Topic = Multiple Subscribers.
BN: Queue = এক consumer পায়
Topic = একাধিক subscription পায়।


7. What is a Dead Letter Queue (DLQ)?

EN: A sub-queue where failed messages are stored.
BN: যেসব মেসেজ প্রসেস করা যায় না, সেগুলো রাখার জন্য DLQ ব্যবহার হয়।


8. Why do messages go to DLQ?

EN: TTL expire, max delivery count exceeded, processing errors.
BN: TTL শেষ হওয়া, বারবার প্রসেস ব্যর্থ হওয়া, errors।


9. What is Message TTL?

EN: A time limit after which a message becomes invalid.
BN: নির্দিষ্ট সময় পর মেসেজ invalid হয়ে যায়।


10. What is Max Delivery Count?

EN: Number of times Service Bus retries delivering a message.
BN: কতবার retry করে deliver করার চেষ্টা করবে।


11. What are Sessions?

EN: Used for ordered message processing.
BN: Ordered মেসেজ প্রসেস করার জন্য Session ব্যবহার করা হয়।


12. What is Partitioning?

EN: Spreads messages across multiple brokers for high throughput.
BN: Load ভাগ করে throughput বাড়ায়।


13. What is Duplicate Detection?

EN: Service Bus prevents duplicate messages within a time window.
BN: নির্দিষ্ট সময়ে duplicate মেসেজ ব্লক করে।


14. What is PeekLock mode?

EN: A message is locked for a specific receiver but not deleted.
BN: Receiver মেসেজ পড়তে পারে কিন্তু ডিলিট হয় না, locked থাকে।


15. What is Receive and Delete mode?

EN: Deletes message immediately after reading.
BN: মেসেজ পড়ার সাথে সাথেই ডিলিট হয়ে যায়।


16. Which mode ensures no message loss?

EN: PeekLock
BN: PeekLock


17. What is Auto-Forwarding?

EN: Automatically forwards messages from one queue/topic to another.
BN: একটি queue/topic থেকে আরেকটিতে মেসেজ অটো ফরওয়ার্ড করে।


18. What is Scheduled Messaging?

EN: Sending messages to be processed at a future time.
BN: ভবিষ্যতে নির্দিষ্ট সময়ে মেসেজ পাঠানো।


19. What is Deferring a message?

EN: Temporarily postponing processing.
BN: মেসেজ প্রসেস কিছু সময়ের জন্য পিছিয়ে দেওয়া।


20. What is a Subscription Filter?

EN: Rules to decide which message a subscription will receive.
BN: কোন মেসেজ কোন subscription পাবে তা নির্ধারণের নিয়ম।


21. Types of Filters?

EN: SQL Filter, Correlation Filter
BN: SQL Filter, Correlation Filter


22. What is Namespace?

EN: A container for queues, topics, subscriptions.
BN: Queue, Topic, Subscription রাখার কন্টেইনার।


23. What is Shared Access Signature (SAS)?

EN: Token-based authentication method.
BN: Token ভিত্তিক authentication পদ্ধতি।


24. What is AMQP?

EN: Advanced Message Queuing Protocol used for efficient messaging.
BN: কার্যকর মেসেজিংয়ের জন্য ব্যবহৃত একটি প্রোটোকল।


25. Difference between AMQP and HTTPS?

EN: AMQP = faster, duplex.
HTTPS = simpler, slower.
BN: AMQP = দ্রুত, দুই‑দিকের যোগাযোগ
HTTPS = সহজ, ধীরগতি।


26. What is Prefetch Count?

EN: Number of messages fetched in advance.
BN: আগেই একসাথে কিছু মেসেজ টেনে আনা।


27. What is Message Lock Duration?

EN: Duration a message remains locked in PeekLock.
BN: PeekLock‑এ মেসেজ কত সময় locked থাকবে।


28. Can a Topic have multiple subscriptions?

EN: Yes.
BN: হ্যাঁ।


29. Can a Queue have multiple receivers?

EN: Yes, but each message goes to only one.
BN: রিসিভার একাধিক হতে পারে, কিন্তু মেসেজ একটির কাছে যাবে।


30. What is Geo-Disaster Recovery?

EN: Cross-region failover.
BN: Region-wide সমস্যায় backup region এ স্যুইচ।


31. Standard vs Premium differences?

EN:

  • Premium = Dedicated compute, higher throughput
  • Standard = Shared infrastructure
    BN:
  • Premium = Dedicated resources, বেশি throughput
  • Standard = Shared resources

32. Can Service Bus trigger Azure Functions?

EN: Yes.
BN: হ্যাঁ।


33. What is Dead-letter Reason?

EN: Explains why message went to DLQ.
BN: কেন DLQ‑এ গেল তা দেখায়।


34. Maximum message size?

EN:

  • Standard: 256 KB
  • Premium: 1 MB
    BN:
  • Standard: 256 KB
  • Premium: 1 MB

35. Is FIFO supported?

EN: Yes, via Sessions.
BN: হ্যাঁ, Session ব্যবহার করে।


36. What is Service Bus Explorer?

EN: Tool to manage and test Service Bus.
BN: Service Bus টেস্ট ও ম্যানেজ করার টুল।


37. What are Message Properties?

EN: Custom key-value meta-data.
BN: কাস্টম কী-ভ্যালু তথ্য।


38. Queues vs Storage Queues?

EN:
Service Bus = enterprise, ordering, sessions
Storage Queue = simple, cheap
BN:
Service Bus = এন্টারপ্রাইজ, ordering সহ
Storage Queue = সহজ, সস্তা


39. What is Auto-Complete?

EN: Auto deletes message after function completes successfully.
BN: Function সফল হলে মেসেজ নিজে ডিলিট হয়।


40. What is DeadLetter() API?

EN: Manually moves message to DLQ.
BN: মেসেজ manually DLQ‑তে পাঠানো।


41–50: Rapid-fire (Bangla + English)

  1. Batch Receive?
    EN: Receive multiple messages at once.
    BN: একসাথে অনেক মেসেজ রিসিভ করা।

  2. Atomic Transactions?
    EN: Multiple operations as a single unit.
    BN: একাধিক কাজকে একসাথে atomic ভাবে চালানো।

  3. Ordering guarantee?
    EN: Only with sessions.
    BN: শুধু sessions‑এ।

  4. Can we send large files?
    EN: Not recommended; use blob + reference.
    BN: বড় ফাইল নয়; blob এ রেখে রেফারেন্স পাঠান।

  5. Poison Messages?
    EN: Messages that always fail processing.
    BN: বারবার error হওয়া মেসেজ।

  6. Auto Delete on Idle?
    EN: Deletes unused subscriptions after inactivity.
    BN: দীর্ঘ সময় ব্যবহার না হলে subscription ডিলিট হয়।

  7. What is CorrelationId?
    EN: Used to match related messages.
    BN: related মেসেজ track করতে ব্যবহৃত।

  8. Can Service Bus work offline?
    EN: No (cloud service).
    BN: না (cloud service)।

  9. What is Message Deferral Id?
    EN: ID needed to retrieve deferred message.
    BN: deferred মেসেজ ফেরত আনার জন্য আইডি।

  10. How to reprocess DLQ messages?
    EN: Read and send to main queue again.
    BN: DLQ থেকে পড়ে আবার main queue‑তে পাঠানো।


Thursday, October 22, 2020

Web API

 Pipeline in MVC

https://www.c-sharpcorner.com/article/mvc-architecture-its-pipeline4/

We can say that pipeline of MVC contains the following processes,

  • Routing
  • Controller Initialization
  • Action Execution
  • Result Execution
  • View Initialization and Rendering

  • Routing is the first step in ASP.NET MVC pipeline.
  • After finding the route successfully, ProcessRequest() method is invoked
While the ProcessRequest() method is invoked, it uses the IControllerFactory instance to create the controller for the URL request
After initialization of controller it has the information about the action method, this detail of action method is passed to controller’s InvokeAction() method

View Engine takes ViewResult type and renders it as a View and shows it by using IView

MVC
 Model?
It is basically a business entity which is used to represent the application data.
it's the presentation layer of ASP.Net MVC.
Controller
The Controller is responsible for taking the end user request and loading the appropriate Model and View.

Web API Security

There are two technique for security in Web API. one is basic authentication and second is token based authorization. We can also maintain session using token based atuhorization.













  1. Serialization:
Person person = new Person { Name = "John", Age = 30, City = "New York" }; string serializedData = JsonSerializer.Serialize(person);

The JsonSerializer.Serialize() method is used to serialize the person object into a JSON string.
  1. Deserialization:
  2. string jsonString = "{\"Name\":\"John\",\"Age\":30,\"City\":\"New York\"}";Person deserializedPerson = JsonSerializer.Deserialize<Person>(jsonString);
  3. In the deserialization example, we have a JSON string jsonString representing the serialized data. The JsonSerializer.Deserialize<T>() method is used to deserialize the JSON string back into a Person object.
The System.Text.Json namespace provides the JsonSerializer class, which offers serialization and deserialization capabilities using JSON format. It's available in .NET Core and .NET 5.0 and later versions.







Session, Cookie, JWT, Token, SSO, and OAuth 2.0 Explained in One Diagram

When you login to a website, your identity needs to be managed. Here is how different solutions work:

- Session - The server stores your identity and gives the browser a session ID cookie. This allows the server to track login state. But cookies don't work well across devices.

- Token - Your identity is encoded into a token sent to the browser. The browser sends this token on future requests for authentication. No server session storage is required. But tokens need encryption/decryption.

- JWT - JSON Web Tokens standardize identity tokens using digital signatures for trust. The signature is contained in the token so no server session is needed.

- SSO - Single Sign On uses a central authentication service. This allows a single login to work across multiple sites.

- OAuth2 - Allows limited access to your data on one site by another site, without giving away passwords.

- QR Code - Encodes a random token into a QR code for mobile login. Scanning the code logs you in without typing a password.

Over to you: QR code logins are gaining popularity. Do you know how it works?




JWTs (JSON Web Tokens) are split into three pieces:

✑ Header - Provides information about how to validate the token including information about the type of token and how it was signed.

✑ Payload - Contains all of the important data about the user or app that is attempting to call your service.

✑ Signature - Is the raw material used to validate the token.


OutSystems

 https://www.youtube.com/watch?v=sNbSINPbE58&list=PLZorY18qtX6GK10LgrCwgWPO6BeB5HsgW&index=5