Friday, January 19, 2018

MassTransit–No queue is created

Yesterday, I was working on a new project where we planned to use MassTransit. After creating the RabbitMQ configuration and publishing a first message, I noticed that an Exchange was created in RabbitMQ but that it was not bound to a queue. This resulted in the fact that the message was lost Sad smile.

Here is the related code:

In the RabbitMQ administration I saw the following in the list of Exchanges:

image

But when I clicked on the Exchange to view the details, I saw that the exchange was not linked to any queue:

image

As I found out, this is expected behavior in MassTransit.

From StackOverflow:

Publishing a message does not create any queues. Queues are created when receive endpoints are added to a bus. Until the receive endpoints are started, and their topology configured in RabbitMQ (the exchange-exchange-queue bindings), any messages published are not delivered because there are no bindings to any queues. Once the receive endpoints are started, those bindings exist and messages will be delivered to the queues.

Thursday, January 18, 2018

Entity Framework Core: Log parameter values

Entity Framework Core provides a rich logging mechanism that allows you to see what’s going on behind the scenes. If you register EF Core in your ASP.NET Core application using the AddDbContext method, it will integrate automatically with the logging mechanism of ASP.NET Core.

Otherwise you have a little bit extra work and should register a LoggerFactory yourself(more information here: https://docs.microsoft.com/en-us/ef/core/miscellaneous/logging)

Unfortunately after enabling it, I still couldn’t see the query parameters that were used by the EF queries. This is a security feature that is enabled by default. As query parameters can contain sensitive information, it is excluded by default from the log messages. To include this information you have to explicitly enable it by calling EnableSensitiveDataLogging():

From the documentation

Enables application data to be included in exception messages, logging, etc. This can include the values assigned to properties of your entity instances, parameter values for commands being sent to the database, and other such data. You should only enable this flag if you have the appropriate security measures in place based on the sensitivity of this data.

You have to add this code to the OnConfiguring method of your DbContext:

Wednesday, January 17, 2018

ElasticSearch debugging–Log request and response messages using NEST

It can sometimes be quiet hard to figure out why a specific ElasticSearch query fails or don’t returns the expected results. As I’m using NEST, the high-level ElasticSearch client, it is not always obvious what is exactly happening behind the scenes.

Here is a code snippet that allows you to log the generated request and response messages:

Remark: Using this code has a performance impact, so only use it for development or testing purposes.

Tuesday, January 16, 2018

Debugging a .NET Core project in VS 2017 - Unable to start program, An operation is not legal in the current state

When trying to debug a .NET Core application using Visual Studio 2017, attaching the debugger suddenly started to fail with the following error message:

Unable to start program, An operation is not legal in the current state

Starting without a debugger attached worked, but attaching the debugger later on didn’t. Rebuilding my project, restarting Visual Studio, restarting my PC, all seemed to not bring a solution to the table.

This is a known issue, the solution (workaround) is to turn off JavaScript debugging on Chrome:

  • Go to Tools –> Options –> Debugging –> General
  • Turn off the setting for Enable JavaScript Debugging for ASP.NET (Chrome and IE)

image

Remark: A fix will be provided in the Visual Studio 2017 15.6 release.

Monday, January 15, 2018

StructureMap: Using the IoC container inside the Registry

StructureMap has an easy to use Registry DSL that can be used in a Registry class. By using (one or more) Registry classes you can group all your IoC plumbing together.

Yesterday I had a situation where I wanted to use some object that was already registered in the IoC container in the registration of another class. This is possible by passing an IContext as a second parameter of the Use() method in the fluent API:

Friday, January 12, 2018

F# with .NET Core in Visual Studio

Microsoft has supported F# on .NET Core from the beginning. Unfortunately the same story is not true when we talk about Visual Studio integration. Before, if you wanted to use F# in combination with .NET Core, you had to use VS Code. 

With the release of Visual Studio 2017 15.5, this has finally changed and Visual Studio integration is available.

image

image

Thursday, January 11, 2018

Postman API network

Yesterday I mentioned that reading other peoples code is a great way to extend your skills as a developer. A similar thing can be said about looking at other people their (REST) api’s…

A good starting point is the Postman API Network, a directory of public APIs available maintained by the creators of the Postman app.

image

Every API listed in this directory includes a complete Postman collection, that can be directly consumed from the Postman app.

image