예제 #1
0
        public void CanSendEmail()
        {
            var queueStreamName  = "Test" + EventStoreQueueConstants.QueueStreamName;
            var outboxStreamName = "Test" + EventStoreQueueConstants.OutboxStreamName;

            var mainLog = LogManager.GetLoggerFor("TEST");

            // EventStoreSettings
            var eventStoreIp      = "127.0.0.1";
            var eventStoreTcpPort = 1113;
            var eventStoreUser    = "******";
            var eventStorePass    = "******";

            // Conectando el EventStore
            var eventStoreSettings = ConnectionSettings
                                     .Create()
                                     .KeepReconnecting()
                                     .SetHeartbeatTimeout(TimeSpan.FromSeconds(30))
                                     .SetDefaultUserCredentials(new UserCredentials(eventStoreUser, eventStorePass))
                                     .Build();

            var tcp              = new IPEndPoint(IPAddress.Parse(eventStoreIp), eventStoreTcpPort);
            var connection       = EventStoreConnection.Create(eventStoreSettings, tcp);
            var connectionSource = "local";

            connection.Closed += (s, e) =>
                                 mainLog.Error($"The {connectionSource} ES connection was closed");
            connection.Connected += (s, e) =>
                                    mainLog.Log($"The connection with {connectionSource} ES was establised");
            connection.Disconnected += (s, e) =>
                                       mainLog.Log($"The connection with {connectionSource} ES was lost");
            connection.Reconnecting += (s, e) =>
                                       mainLog.Log($"Reconnecting with {connectionSource} ES");
            connection.ConnectAsync().Wait();

            var serializer = new JsonSerializer();

            var repo = new EventSourcedRepository(connection, serializer, enablePersistentSnapshotting: true, snapshotInterval: 1);

            var client = new SimpleEmailSenderEsClient(connection, serializer, queueStreamName);

            var mail = EmailFactory.NewFrom("Alexis", "*****@*****.**")
                       .To("Alexis", "*****@*****.**")
                       .Subject("Test")
                       .BodyUsingTemplateFromFile(@"~/testmail.html", new { Name = "Chary" })
                       .Build();

            client.Send(mail);

            // Consuming
            //var sender = new FakeEmailSender("mail.fecoprod.com.py", 25);
            var sender = new WaitEmailSender("mail.fecoprod.com.py", 25);

            using (var job = new MailSendingJob(connection, repo, serializer, sender, queueStreamName, outboxStreamName))
            {
                job.Start();

                sender.WaitForSending();
            }
        }