static async Task Main(string[] args) { using var actorSystem = ActorSystem.Create("poc"); using var mat = actorSystem.Materializer(); var connectionSettings = AmqpConnectionDetails.Create("localhost", 5672) .WithCredentials(AmqpCredentials.Create("mirero", "system")) .WithAutomaticRecoveryEnabled(true) .WithNetworkRecoveryInterval(TimeSpan.FromSeconds(1)); var queueName = "Amqp_Test_1"; var queueDeclation = QueueDeclaration.Create(queueName) .WithDurable(false) .WithAutoDelete(true); var amqpSink = AmqpSink.CreateSimple(AmqpSinkSettings.Create(connectionSettings) .WithRoutingKey(queueName) .WithDeclarations(queueDeclation)); var amqpSource = AmqpSource.CommittableSource(NamedQueueSourceSettings.Create(connectionSettings, queueName) .WithDeclarations(queueDeclation), 1); var input = new[] { "one", "two", "three", "four", "five" }; await Source.From(input) .Select(ByteString.FromString) .RunWith(amqpSink, mat); await actorSystem.Terminate(); }
public AmqpConnectorsTest(AmqpFixture fixture, ITestOutputHelper output) : base((ActorSystem)null, output) { _mat = ActorMaterializer.Create(Sys); _connectionSettings = AmqpConnectionDetails .Create(fixture.HostName, fixture.AmqpPort) .WithCredentials(AmqpCredentials.Create(fixture.UserName, fixture.Password)) .WithAutomaticRecoveryEnabled(true) .WithNetworkRecoveryInterval(TimeSpan.FromSeconds(1)); _fixture = fixture; }
public void PublishAndConsume() { var connectionSettings = AmqpConnectionDetails.Create("localhost", 5672).WithAutomaticRecoveryEnabled(true).WithNetworkRecoveryInterval(TimeSpan.FromSeconds(1)); var exchange = ExchangeDeclaration.Create("logs", "topic"); //queue declaration var queueName = "amqp-conn-it-spec-simple-queue-" + Environment.TickCount; var queueDeclaration = QueueDeclaration.Create(queueName).WithDurable(false).WithAutoDelete(true); //create sink var amqpSink = AmqpSink.CreateSimple( AmqpSinkSettings.Create(connectionSettings) .WithRoutingKey(queueName) .WithDeclarations(queueDeclaration)); //create source int bufferSize = 10; var amqpSource = AmqpSource.Create( NamedQueueSourceSettings.Create(DefaultAmqpConnection.Instance, queueName) .WithDeclarations(queueDeclaration), bufferSize); //run sink var input = new List <string> { "one", "two", "three", "four", "five" }; Source.From(input).Select(ByteString.FromString).RunWith(amqpSink, _materializer).Wait(); //run source var result = amqpSource.Select(m => m.Bytes.ToString(Encoding.UTF8)) .Take(input.Count) .RunWith(Sink.Seq <string>(), _materializer); result.Wait(TimeSpan.FromSeconds(3)); Assert.Equal(input, result.Result); }
public static Source <CommittableIncomingMessage, Akka.NotUsed> CommittableQueue(Action <SimpleQueueOptions> opt) { var option = new SimpleQueueOptions(); opt.Invoke(option); var connectionSettings = AmqpConnectionDetails.Create(option.HostAndPorts.First().Host, option.HostAndPorts.First().Port) .WithHostsAndPorts(option.HostAndPorts.First(), option.HostAndPorts.ToArray()) .WithCredentials(AmqpCredentials.Create(option.UserName, option.Password)) .WithAutomaticRecoveryEnabled(true) .WithNetworkRecoveryInterval(TimeSpan.FromSeconds(1)) .WithVirtualHost(option.VirtualHost); var queueDeclaration = QueueDeclaration.Create(option.QueueName) .WithDurable(false) .WithAutoDelete(false); return(AmqpSource.CommittableSource(NamedQueueSourceSettings.Create(connectionSettings, option.QueueName) .WithDeclarations(queueDeclaration), 1)); }
public static Sink <ByteString, Task> Simple(Action <SimpleQueueOptions> opt) { var option = new SimpleQueueOptions(); opt.Invoke(option); var connectionSettings = AmqpConnectionDetails.Create(option.HostAndPorts.First().Host, option.HostAndPorts.First().Port) .WithHostsAndPorts(option.HostAndPorts.First(), option.HostAndPorts.ToArray()) .WithCredentials(AmqpCredentials.Create(option.UserName, option.Password)) .WithAutomaticRecoveryEnabled(true) .WithNetworkRecoveryInterval(TimeSpan.FromSeconds(1)) .WithVirtualHost(option.VirtualHost ?? "/"); var queueDeclaration = QueueDeclaration.Create(option.QueueName) .WithDurable(false) .WithAutoDelete(false); return(AmqpSink.CreateSimple(AmqpSinkSettings.Create(connectionSettings) .WithRoutingKey(option.QueueName) .WithDeclarations(queueDeclaration))); }