concept event consumer in category .net

appears as: event consumer
Microservices in .NET Core, Second Edition

This is an excerpt from Manning's book Microservices in .NET Core, Second Edition.

Next up we build a container image for LoyaltyProgram microservice. The Loyalty Program has two parts: The API and the event consumer. We will build one container that is capable on running either as the API or the event consumer based on an environment variable. To do that we create a Dockerfile in the LoyaltyProgram code base where the ENTRYPOINT is controlled by an environment variable:

Listing 5.14. One docker image for the LoyaltyProgram which can run either the API of the event consumer
language="sql" linenumbering="unnumbered">FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY . .
RUN dotnet restore "LoyaltyProgram/LoyaltyProgram.csproj"
RUN dotnet restore "EventConsumer/EventConsumer.csproj"
WORKDIR "/src/LoyaltyProgram"
RUN dotnet build "LoyaltyProgram.csproj" -c Release -o /api/build  #1
WORKDIR "/src/EventConsumer"
RUN dotnet build "EventConsumer.csproj" -c Release -o /consumer/build/consumer #2

FROM build AS publish
WORKDIR "/src/LoyaltyProgram"
RUN dotnet publish "LoyaltyProgram.csproj" -c Release -o /api/publish   #3
WORKDIR "/src/EventConsumer"
RUN dotnet publish "EventConsumer.csproj" -c Release -o /consumer/publish  #4

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS final
WORKDIR /app
EXPOSE 80
COPY --from=publish /api/publish ./api
COPY --from=publish /consumer/publish ./consumer
ENTRYPOINT dotnet $STARTUPDLL                                     #5

This Dockerfile is a little different from what we have seen before. The Dockerfiles we have seen before have built and published one ASP.NET Core application. This one builds and publishes an ASP.NET Core application - the Loyalty Program - and a .NET Core console application - the event consumer. The image built with this Dockerfile will therefore have both the LoyaltyProgram.dll and the EventConsumer.dll in it. The last line of the Dockerfile, ENTRYPOINT dotnet $STARTUPDLL says that when the images built with this Dockerfile starts up they should run dotnet on whatever the environment variable $STARTUPDLL points to. So id $STARTUPDLL is equal to the path to the LoyaltyProgram.dll the image will run the Loyalty Program API and it '$STARTUPDLL' is equal to the path to the EventConsumer.dll the image will run the Loyalty Program event consumer.