Skip to content

Commit

Permalink
adding Producer layer
Browse files Browse the repository at this point in the history
  • Loading branch information
farhadzm committed Apr 30, 2021
1 parent 8498f91 commit 15cff8e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
32 changes: 32 additions & 0 deletions RabbitMq/RabbitMq.Producer/Conrtrollers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Microsoft.AspNetCore.Mvc;
using RabbitMq.Common.Services;
using RabbitMQ.Client;
using System.Text;

namespace RabbitMq.Producer.Conrtrollers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class HomeController : ControllerBase
{
private readonly IRabbitMqService _rabbitMqService;

public HomeController(IRabbitMqService rabbitMqService)
{
_rabbitMqService = rabbitMqService;
}
[HttpPost]
public IActionResult SendMessage()
{
using var connection = _rabbitMqService.CreateChannel();
using var model = connection.CreateModel();
var body = Encoding.UTF8.GetBytes("Hi");
model.BasicPublish("UserExchange",
string.Empty,
basicProperties: null,
body: body);

return Ok();
}
}
}
4 changes: 4 additions & 0 deletions RabbitMq/RabbitMq.Producer/RabbitMq.Producer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\RabbitMq.Common\RabbitMq.Common.csproj" />
</ItemGroup>

</Project>
11 changes: 11 additions & 0 deletions RabbitMq/RabbitMq.Producer/RabbitMq.Producer.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup>
<ActiveDebugProfile>RabbitMq.Producer</ActiveDebugProfile>
<Controller_SelectedScaffolderID>ApiControllerEmptyScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath>root/Common/Api</Controller_SelectedScaffolderCategoryPath>
</PropertyGroup>
</Project>
15 changes: 9 additions & 6 deletions RabbitMq/RabbitMq.Producer/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using RabbitMq.Common.Extensions;


namespace RabbitMq.Producer
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; set; }
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddCommonService(Configuration);
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
Expand Down

0 comments on commit 15cff8e

Please sign in to comment.