Posts

Showing posts from 2020

C# Producer Consumer using Rabbit MQ

So I've been learning about the different message queuing systems and discovered rabbit MQ, an open source and very popular message queuing system. I've created a very basic producer/consumer system that sends a message to a rabbit MQ queue. Producer/Consumer is pretty simple, you have two systems a producer that writes to a queue and a consumer that reads from a queue. This is desirable because it splits responsibility and allows for scalability. The code below is going to assume you have a rabbit MQ instance installed on your local machine. You can get rabbit MQ here:  https://www.rabbitmq.com/ Now the code is broken down into 3 parts, the main program, the producer, and the consumer. This is a basic example so its using old school threading rather than the new async/await .net prefers. But this is just to show how to use rabbit MQ in C# and to demonstrate a producer/consumer example. You will need to make sure your project has the rabbit MQ client nuget package installed

C# DateTime Formatting

C# Offers a wide variety of formatting date times using the ToString method. Below you will see the various options you can use and the results. Format Result DateTime.Now.ToString("MM/dd/yyyy") 05/29/2015 DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015 DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015 05:50 DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015 05:50 AM DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015 5:50 DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015 5:50 AM DateTime.Now.ToString("dddd, dd MMMM yyyy HH:mm:ss") Friday, 29 May 2015 05:50:06 DateTime.Now.ToString("MM/dd/yyyy HH:mm") 05/29/2015 05:50 DateTime.Now.ToString("MM/dd/yyyy hh:mm tt") 05/29/2015 05:50 AM DateTime.Now.ToString("MM/dd/yyyy H:mm") 05/29/2015 5:50 DateTime.Now.ToString("MM/dd/yyyy h:mm tt") 05/29/2015 5:5

C# Getting your IP address

Sometimes you need to know your ip address in code. With the following snippet you can! var hostName= new HostInformation(); var address = Dns.GetHostEntry(hostName).AddressList[0].ToString();