Thursday, 25 July 2019

Difference between IEnumerable and IEnumerator

Difference between IEnumerable and IEnumerator

IEnumerable:

1. Make the syntax sorter.
2. IEnumerable uses IEnumerator internally
3. IEnumerable does not remember state(currently which row is currently through)

IEnumerator:

IEnumerable does remember state(currently which row is currently through)


List<int> years = new List<int>();
years.Add(2000);
years.Add(2001);
years.Add(2002);
years.Add(2003);
years.Add(2004);
years.Add(2005);

IEnumerable<int> ienum = (IEnumerable<int>)years;
ienum.GetEnumerator();//IEnumerable uses IEnumerator internally.

foreach(int i in ienum){
Console.WriteLine(i);
}


IEnumerator<int> ienumerat = year.GetEnumerator();

while(ienumerat.MoveNext()){
Console.WriteLine(ienumerat.Current.ToString());
}

https://www.youtube.com/watch?v=jd3yUjGc9M0

Monday, 15 July 2019

Masstransit .NET Messaging

Masstransit .NET Messaging

MassTransit

1. It is a message transport
2. Free, open source, lightweight message bus for creating distributed applications using the .NET framework. 

Features:

1. Developer friendly way to asynchronously connect services
2. Message-based communication is a reliable and scalable way to implement a service oriented architecture
3. Schedule a message in future delivery

Consume: Read a message from Queue
Publish: Send a message to Queue

Can use message brokers -- RabbitMQ (the Default), Azure Service Bus

https://masstransit-project.com/

Message brokers - MSMQ - RabbitMQ - Azure Service Bus

Message brokers:

Below are the message service brokers. those are used to store messages and consume the messages
and each broker has some other features.

1. MSMQ
2. RabbitMQ
3. Azure Service Bus

MSMQ- Microsoft Message Queuing
1. MSMQ is a message queue implementation developed by Microsoft.
2. It deployed in its Windows Server operating systems.
3. It is a messaging protocol.
4. MSMQ ensures reliable delivery by placing messages that fail to reach their intended destination
 in a queue and then resending them once the destination is reachable.
5. MSMQ also supports transactions.

https://docs.microsoft.com/en-us/dotnet/framework/wcf/samples/net-msmq-binding

Dead Queues: 
1. Handel process messages that have failed delivery (undeliverable, deleted, expired etc)
2. It support by using Net Binding - Net MSMQ Binding - Dead letter queue
3. About net msmq binding, end point and binding configuration and contract is explained in the below url
4. Message that is sent to a queue that does not exist.
5. Queue length limit exceeded.
6. Message length limit exceeded.
7. Message is rejected by another queue exchange.
https://docs.microsoft.com/en-us/dotnet/framework/wcf/samples/dead-letter-queues

Poison Message: -- Limited support
1. Poison Message Handling in MSMQ 4.0
2. Schedule a message 
3. Read the message repeatedly from queue when it failed
4. Based on the version of MSMQ, the NetMsmqBinding supports limited detection to full detection of poison messages.
https://docs.microsoft.com/en-us/dotnet/framework/wcf/samples/poison-message-handling-in-msmq-4-0


Session and Queues: 
Group of messages is processed by single request
Queued sessions are a mechanism used to send and receive a related set of messages that must get processed all at once.
a client sends a set of messages that are related to each other in a group. When messages must be processed together or in a specified order, a queue can be used to group them together, for processing by a single receiving application

Volatile Message:
msmq - makes to best effort to deliver the message(success/failure) with no assurances.
You may want to send a volatile message with no assurances over a queue, when timely delivery is more important than losing messages. Volatile messages do not survive queue manager crashes. Therefore if the queue manager crashes, the non-transactional queue used to store volatile messages survives

 You cannot send volatile messages with no assurances within the scope of a transaction using MSMQ. You also must create a non-transactional queue to send volatile messages.


By using Net MSMQ - Dotnet - WCF - We can achieve below features
1. Two - way communication
2. Dead letter queue
3. Poison message
4. Message security
5. Session and Queues

RabbitMQ:
https://www.rabbitmq.com/
1. RabbitMQ is the most popular open source message broker.
2. Runs on many operating systems and cloud environments,

Features:
1. Asynchronous Messaging
2. Multiple messaging protocols 
3. Message queuing
4. Delivery acknowledgement
5. Flexible routing to queues
6. Multiple exchange type.
7. Pluggable Authentication and Authorization. 
8. By default supports - Transport Layer Security (TLS) is the successor protocol to SSL. TLS is an improved version of SSL.
9. supports LDAP to perform authentication and authorisation






Monday, 8 July 2019

Clustered and Non-Clustered Indexes in SQL?

Clustered and Non-Clustered Indexes in SQL?

Clustered:  The index defines the order in which data is physically stored in a table.
1. Only one clustered index per table.
2. Primary key constraint automatically creates a clustered index
2. Order in which data is physically stored in a table

To retrieves the indexes:
EXECUTE sp_helpindex Appointment

Non-Clustered: 

This allows for more than one non-clustered index per table.

CREATE NONCLUSTERED INDEX Appointment_PatientId
ON Appointment(PatientId ASC)

EXISTS vs IN -- Which is faster in SQL


EXISTS vs IN -- Which is faster

Based on rule optimizer:

--> EXISTS is much faster than IN, when the sub-query results is very large.

--> IN is faster than EXISTS, when the sub-query results is very small.
Based on cost optimizer:

There is no difference.