Fix listening for AMQP messages, remove test console app
This commit is contained in:
parent
8c6037b010
commit
90cbf7ae81
@ -67,8 +67,7 @@ namespace Api.AMQPReciever
|
|||||||
|
|
||||||
await channel.BasicConsumeAsync(queue, true, consumer);
|
await channel.BasicConsumeAsync(queue, true, consumer);
|
||||||
|
|
||||||
Console.WriteLine("Press enter to exit.");
|
while (true);
|
||||||
Console.ReadLine();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<OutputType>Exe</OutputType>
|
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="RabbitMQ.Client" Version="7.1.2" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -1,25 +0,0 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
|
||||||
# Visual Studio Version 17
|
|
||||||
VisualStudioVersion = 17.9.34607.119
|
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp1", "ConsoleApp1.csproj", "{0BC93CF2-F92D-4DD6-83BE-A985CBB74960}"
|
|
||||||
EndProject
|
|
||||||
Global
|
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
||||||
Debug|Any CPU = Debug|Any CPU
|
|
||||||
Release|Any CPU = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
|
||||||
{0BC93CF2-F92D-4DD6-83BE-A985CBB74960}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{0BC93CF2-F92D-4DD6-83BE-A985CBB74960}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{0BC93CF2-F92D-4DD6-83BE-A985CBB74960}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{0BC93CF2-F92D-4DD6-83BE-A985CBB74960}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
|
||||||
HideSolutionNode = FALSE
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
|
||||||
SolutionGuid = {55EE0E94-4585-4E79-AC67-4B0E809E99AB}
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
|
@ -1,52 +0,0 @@
|
|||||||
using RabbitMQ.Client;
|
|
||||||
using RabbitMQ.Client.Events;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
|
|
||||||
var factory = new ConnectionFactory();
|
|
||||||
var queue = "test";
|
|
||||||
|
|
||||||
|
|
||||||
factory.UserName = "h5";
|
|
||||||
factory.Password = "Merc1234";
|
|
||||||
factory.HostName = "10.135.51.116";
|
|
||||||
factory.Port = 5672;
|
|
||||||
|
|
||||||
using var conn = await factory.CreateConnectionAsync();
|
|
||||||
Console.WriteLine("AMQPClien connected");
|
|
||||||
using var channel = await conn.CreateChannelAsync();
|
|
||||||
|
|
||||||
await channel.QueueDeclareAsync(queue: queue, durable: false, exclusive: false, autoDelete: false);
|
|
||||||
Console.WriteLine($"{queue} connected");
|
|
||||||
|
|
||||||
var consumer = new AsyncEventingBasicConsumer(channel);
|
|
||||||
consumer.ReceivedAsync += (model, ea) =>
|
|
||||||
{
|
|
||||||
Console.WriteLine("Received application message.");
|
|
||||||
var body = ea.Body.ToArray();
|
|
||||||
var message = Encoding.UTF8.GetString(body);
|
|
||||||
Console.WriteLine(message);
|
|
||||||
|
|
||||||
return Task.CompletedTask;
|
|
||||||
};
|
|
||||||
|
|
||||||
await channel.BasicConsumeAsync(queue, true, consumer);
|
|
||||||
|
|
||||||
|
|
||||||
const string message = "Hello World!";
|
|
||||||
var body = Encoding.UTF8.GetBytes(message);
|
|
||||||
await channel.BasicPublishAsync(exchange: string.Empty, routingKey: queue, body: body);
|
|
||||||
Console.WriteLine(" Press enter to continue.");
|
|
||||||
Console.ReadLine();
|
|
||||||
await channel.BasicPublishAsync(exchange: string.Empty, routingKey: queue, body: body);
|
|
||||||
Console.WriteLine(" Press enter to continue.");
|
|
||||||
Console.ReadLine();
|
|
||||||
await channel.BasicPublishAsync(exchange: string.Empty, routingKey: queue, body: body);
|
|
||||||
Console.WriteLine(" Press enter to continue.");
|
|
||||||
Console.ReadLine();
|
|
||||||
await channel.BasicPublishAsync(exchange: string.Empty, routingKey: queue, body: body);
|
|
||||||
Console.WriteLine(" Press enter to continue.");
|
|
||||||
Console.ReadLine();
|
|
||||||
await channel.BasicPublishAsync(exchange: string.Empty, routingKey: queue, body: body);
|
|
||||||
Console.WriteLine(" Press enter to exit.");
|
|
||||||
Console.ReadLine();
|
|
Loading…
Reference in New Issue
Block a user