Merge branch 'release/2.7.2'

This commit is contained in:
Mark van Renswoude 2021-09-09 15:11:52 +02:00
commit 63c3e7f25f
13 changed files with 138 additions and 140 deletions

View File

@ -17,6 +17,9 @@ namespace Tapeti.Cmd
.Where(t => t.GetCustomAttribute<ExecutableVerbAttribute>() != null)
.ToArray();
using var consoleWrapper = new ConsoleWrapper();
// ReSharper disable AccessToDisposedClosure
CommandLine.Parser.Default.ParseArguments(args, verbTypes.ToArray())
.WithParsed(o =>
{
@ -28,33 +31,33 @@ namespace Tapeti.Cmd
// Should have been validated by the ExecutableVerbAttribute
Debug.Assert(executer != null, nameof(executer) + " != null");
using var consoleWrapper = new ConsoleWrapper();
executer.Execute(consoleWrapper);
exitCode = 0;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
DebugConfirmClose();
using var consoleWriter = consoleWrapper.GetPermanentWriter();
consoleWriter.WriteLine(e.Message);
DebugConfirmClose(consoleWrapper);
}
})
.WithNotParsed(_ =>
{
DebugConfirmClose();
DebugConfirmClose(consoleWrapper);
});
// ReSharper restore AccessToDisposedClosure
return exitCode;
}
private static void DebugConfirmClose()
private static void DebugConfirmClose(IConsole console)
{
if (!Debugger.IsAttached)
return;
Console.WriteLine("Press any Enter key to continue...");
Console.ReadLine();
using var consoleWriter = console.GetPermanentWriter();
consoleWriter.Confirm("Press any key to continue...");
}
}
}

View File

@ -241,6 +241,7 @@ namespace Tapeti.Cmd.Serialization
if (!string.IsNullOrEmpty(ClusterId)) properties.ClusterId = ClusterId;
if (!string.IsNullOrEmpty(ContentEncoding)) properties.ContentEncoding = ContentEncoding;
if (!string.IsNullOrEmpty(ContentType)) properties.ContentType = ContentType;
if (!string.IsNullOrEmpty(CorrelationId)) properties.CorrelationId = CorrelationId;
if (DeliveryMode.HasValue) properties.DeliveryMode = DeliveryMode.Value;
if (!string.IsNullOrEmpty(Expiration)) properties.Expiration = Expiration;
if (!string.IsNullOrEmpty(MessageId)) properties.MessageId = MessageId;

View File

@ -1,22 +1,93 @@
using CommandLine;
using System;
using CommandLine;
using RabbitMQ.Client;
using Tapeti.Cmd.ConsoleHelper;
namespace Tapeti.Cmd.Verbs
{
public class BaseConnectionOptions
{
[Option('h', "host", HelpText = "Hostname of the RabbitMQ server.", Default = "localhost")]
[Option('h', "host", HelpText = "(Default: localhost) Hostname of the RabbitMQ server. Can also be set using the TAPETI_HOST environment variable.")]
public string Host { get; set; }
[Option("port", HelpText = "AMQP port of the RabbitMQ server.", Default = 5672)]
public int Port { get; set; }
[Option("port", HelpText = "(Default: 5672) AMQP port of the RabbitMQ server. Can also be set using the TAPETI_PORT environment variable.")]
public int? Port { get; set; }
[Option('v', "virtualhost", HelpText = "Virtual host used for the RabbitMQ connection.", Default = "/")]
[Option('v', "virtualhost", HelpText = "(Default: /) Virtual host used for the RabbitMQ connection. Can also be set using the TAPETI_VIRTUALHOST environment variable.")]
public string VirtualHost { get; set; }
[Option('u', "username", HelpText = "Username used to connect to the RabbitMQ server.", Default = "guest")]
[Option('u', "username", HelpText = "(Default: guest) Username used to connect to the RabbitMQ server. Can also be set using the TAPETI_USERNAME environment variable.")]
public string Username { get; set; }
[Option('p', "password", HelpText = "Password used to connect to the RabbitMQ server.", Default = "guest")]
[Option('p', "password", HelpText = "(Default: guest) Password used to connect to the RabbitMQ server. Can also be set using the TAPETI_PASSWORD environment variable.")]
public string Password { get; set; }
public ConnectionFactory CreateConnectionFactory(IConsole console)
{
var consoleWriter = console.GetPermanentWriter();
consoleWriter.WriteLine("Using connection parameters:");
var factory = new ConnectionFactory
{
HostName = GetOptionOrEnvironmentValue(consoleWriter, " Host : ", Host, "TAPETI_HOST", "localhost"),
Port = GetOptionOrEnvironmentValue(consoleWriter, " Port : ", Port, "TAPETI_PORT", 5672),
VirtualHost = GetOptionOrEnvironmentValue(consoleWriter, " Virtual host : ", VirtualHost, "TAPETI_VIRTUALHOST", "/"),
UserName = GetOptionOrEnvironmentValue(consoleWriter, " Username : ", Username, "TAPETI_USERNAME", "guest"),
Password = GetOptionOrEnvironmentValue(consoleWriter, " Password : ", Password, "TAPETI_PASSWORD", "guest", true)
};
consoleWriter.WriteLine("");
return factory;
}
private static string GetOptionOrEnvironmentValue(IConsoleWriter consoleWriter, string consoleDisplayName, string optionValue, string environmentName, string defaultValue, bool hideValue = false)
{
string GetDisplayValue(string value)
{
return hideValue
? "<hidden>"
: value;
}
if (!string.IsNullOrEmpty(optionValue))
{
consoleWriter.WriteLine($"{consoleDisplayName}{GetDisplayValue(optionValue)} (from command-line)");
return optionValue;
}
var environmentValue = Environment.GetEnvironmentVariable(environmentName);
if (!string.IsNullOrEmpty(environmentValue))
{
consoleWriter.WriteLine($"{consoleDisplayName}{GetDisplayValue(environmentValue)} (from environment variable)");
return environmentValue;
}
consoleWriter.WriteLine($"{consoleDisplayName}{GetDisplayValue(defaultValue)} (default)");
return defaultValue;
}
private static int GetOptionOrEnvironmentValue(IConsoleWriter consoleWriter, string consoleDisplayName, int? optionValue, string environmentName, int defaultValue)
{
if (optionValue.HasValue)
{
consoleWriter.WriteLine($"{consoleDisplayName}{optionValue} (from command-line)");
return optionValue.Value;
}
var environmentValue = Environment.GetEnvironmentVariable(environmentName);
if (!string.IsNullOrEmpty(environmentValue) && int.TryParse(environmentValue, out var environmentIntValue))
{
consoleWriter.WriteLine($"{consoleDisplayName}{environmentIntValue} (from environment variable)");
return environmentIntValue;
}
consoleWriter.WriteLine($"{consoleDisplayName}{defaultValue} (default)");
return defaultValue;
}
}
}

View File

@ -35,15 +35,7 @@ namespace Tapeti.Cmd.Verbs
var consoleWriter = console.GetPermanentWriter();
var bindings = BindingParser.Parse(options.Bindings);
var factory = new ConnectionFactory
{
HostName = options.Host,
Port = options.Port,
VirtualHost = options.VirtualHost,
UserName = options.Username,
Password = options.Password
};
var factory = options.CreateConnectionFactory(console);
using var connection = factory.CreateConnection();
using var channel = connection.CreateModel();

View File

@ -37,15 +37,7 @@ namespace Tapeti.Cmd.Verbs
// Parse early to fail early
var bindings = BindingParser.Parse(options.Bindings);
var factory = new ConnectionFactory
{
HostName = options.Host,
Port = options.Port,
VirtualHost = options.VirtualHost,
UserName = options.Username,
Password = options.Password
};
var factory = options.CreateConnectionFactory(console);
using var connection = factory.CreateConnection();
using var channel = connection.CreateModel();

View File

@ -40,15 +40,7 @@ namespace Tapeti.Cmd.Verbs
public void Execute(IConsole console)
{
var consoleWriter = console.GetPermanentWriter();
var factory = new ConnectionFactory
{
HostName = options.Host,
Port = options.Port,
VirtualHost = options.VirtualHost,
UserName = options.Username,
Password = options.Password
};
var factory = options.CreateConnectionFactory(console);
using var messageSerializer = GetMessageSerializer(options);
using var connection = factory.CreateConnection();
using var channel = connection.CreateModel();

View File

@ -1,5 +1,6 @@
using System;
using System;
using System.IO;
using System.Net;
using System.Text;
using CommandLine;
using RabbitMQ.Client;
@ -18,9 +19,12 @@ namespace Tapeti.Cmd.Verbs
[Option('m', "message", Group = "Input", HelpText = "Single message to be sent, in the same format as used for SingleFileJSON. Serialization argument has no effect when using this input.")]
public string InputMessage { get; set; }
[Option('c', "pipe", Group = "Input", HelpText = "Messages are read from the standard input pipe, in the same format as used for SingleFileJSON. Serialization argument has no effect when using this input.")]
public bool InputPipe { get; set; }
[Option("urlencoded", HelpText = "Indicates the message is URL encoded. Only applies to messages passed directly with --message as quotes are very quirky on the command-line, even more so in PowerShell.")]
public bool UrlEncoded { get; set; }
[Option('e', "exchange", HelpText = "If specified publishes to the originating exchange using the original routing key. By default these are ignored and the message is published directly to the originating queue.")]
public bool PublishToExchange { get; set; }
@ -50,16 +54,7 @@ namespace Tapeti.Cmd.Verbs
public void Execute(IConsole console)
{
var consoleWriter = console.GetPermanentWriter();
var factory = new ConnectionFactory
{
HostName = options.Host,
Port = options.Port,
VirtualHost = options.VirtualHost,
UserName = options.Username,
Password = options.Password
};
using var messageSerializer = GetMessageSerializer(options);
var factory = options.CreateConnectionFactory(console); using var messageSerializer = GetMessageSerializer(options);
using var connection = factory.CreateConnection();
using var channel = connection.CreateModel();
var rateLimiter = RateLimiterFactory.Create(console, options.MaxRate, options.BatchSize, options.BatchPauseTime);
@ -133,8 +128,12 @@ namespace Tapeti.Cmd.Verbs
if (!string.IsNullOrEmpty(options.InputMessage))
{
var inputMessage = options.UrlEncoded
? WebUtility.UrlDecode(options.InputMessage)
: options.InputMessage;
disposeStream = true;
return new MemoryStream(Encoding.UTF8.GetBytes(options.InputMessage));
return new MemoryStream(Encoding.UTF8.GetBytes(inputMessage));
}
disposeStream = true;

View File

@ -37,16 +37,7 @@ namespace Tapeti.Cmd.Verbs
return;
}
var factory = new ConnectionFactory
{
HostName = options.Host,
Port = options.Port,
VirtualHost = options.VirtualHost,
UserName = options.Username,
Password = options.Password
};
using var connection = factory.CreateConnection();
var factory = options.CreateConnectionFactory(console); using var connection = factory.CreateConnection();
using var channel = connection.CreateModel();
var messageCount = channel.QueuePurge(options.QueueName);

View File

@ -41,15 +41,7 @@ namespace Tapeti.Cmd.Verbs
return;
}
var factory = new ConnectionFactory
{
HostName = options.Host,
Port = options.Port,
VirtualHost = options.VirtualHost,
UserName = options.Username,
Password = options.Password
};
var factory = options.CreateConnectionFactory(console);
uint messageCount;
try

View File

@ -61,15 +61,7 @@ namespace Tapeti.Cmd.Verbs
public void Execute(IConsole console)
{
var sourceFactory = new ConnectionFactory
{
HostName = options.Host,
Port = options.Port,
VirtualHost = options.VirtualHost,
UserName = options.Username,
Password = options.Password
};
var sourceFactory = options.CreateConnectionFactory(console);
using var sourceConnection = sourceFactory.CreateConnection();
using var sourceChannel = sourceConnection.CreateModel();
@ -78,7 +70,7 @@ namespace Tapeti.Cmd.Verbs
var targetFactory = new ConnectionFactory
{
HostName = !string.IsNullOrEmpty(options.TargetHost) ? options.TargetHost : options.Host,
Port = options.TargetPort ?? options.Port,
Port = options.TargetPort ?? options.Port ?? 5672,
VirtualHost = !string.IsNullOrEmpty(options.TargetVirtualHost) ? options.TargetVirtualHost : options.VirtualHost,
UserName = !string.IsNullOrEmpty(options.TargetUsername) ? options.TargetUsername : options.Username,
Password = !string.IsNullOrEmpty(options.TargetPassword) ? options.TargetPassword : options.Password

View File

@ -35,15 +35,7 @@ namespace Tapeti.Cmd.Verbs
var consoleWriter = console.GetPermanentWriter();
var bindings = BindingParser.Parse(options.Bindings);
var factory = new ConnectionFactory
{
HostName = options.Host,
Port = options.Port,
VirtualHost = options.VirtualHost,
UserName = options.Username,
Password = options.Password
};
var factory = options.CreateConnectionFactory(console);
using var connection = factory.CreateConnection();
using var channel = connection.CreateModel();

View File

@ -42,7 +42,7 @@ namespace Tapeti.Transient
return;
if (map.TryRemove(continuationID, out var tcs))
tcs.SetResult(context.Message);
tcs.TrySetResult(context.Message);
}
@ -86,7 +86,7 @@ namespace Tapeti.Transient
private void TimeoutResponse(object tcs)
{
((TaskCompletionSource<object>)tcs).SetException(new TimeoutException("Transient RequestResponse timed out at (ms) " + defaultTimeoutMs));
((TaskCompletionSource<object>)tcs).TrySetException(new TimeoutException("Transient RequestResponse timed out at (ms) " + defaultTimeoutMs));
}
}
}

View File

@ -10,58 +10,30 @@ before_build:
- ps: build\UpdateVersion.ps1
after_build:
# Tapeti
# Create NuGet packages
- cmd: dotnet pack -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg --output output Tapeti\Tapeti.csproj /p:Configuration=Release /p:Version=%GitVersion_NuGetVersion%
- cmd: appveyor PushArtifact "output\Tapeti.%GitVersion_NuGetVersion%.nupkg"
- cmd: appveyor PushArtifact "output\Tapeti.%GitVersion_NuGetVersion%.snupkg"
# Tapeti.Annotations
- cmd: dotnet pack -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg --output output Tapeti.Annotations\Tapeti.Annotations.csproj /p:Configuration=Release /p:Version=%GitVersion_NuGetVersion%
- cmd: appveyor PushArtifact "output\Tapeti.Annotations.%GitVersion_NuGetVersion%.nupkg"
- cmd: appveyor PushArtifact "output\Tapeti.Annotations.%GitVersion_NuGetVersion%.snupkg"
# Tapeti.DataAnnotations
- cmd: dotnet pack -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg --output output Tapeti.DataAnnotations\Tapeti.DataAnnotations.csproj /p:Configuration=Release /p:Version=%GitVersion_NuGetVersion%
- cmd: appveyor PushArtifact "output\Tapeti.DataAnnotations.%GitVersion_NuGetVersion%.nupkg"
- cmd: appveyor PushArtifact "output\Tapeti.DataAnnotations.%GitVersion_NuGetVersion%.snupkg"
# Tapeti.DataAnnotations.Extensions
- cmd: dotnet pack -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg --output output Tapeti.DataAnnotations.Extensions\Tapeti.DataAnnotations.Extensions.csproj /p:Configuration=Release /p:Version=%GitVersion_NuGetVersion%
- cmd: appveyor PushArtifact "output\Tapeti.DataAnnotations.Extensions.%GitVersion_NuGetVersion%.nupkg"
- cmd: appveyor PushArtifact "output\Tapeti.DataAnnotations.Extensions.%GitVersion_NuGetVersion%.snupkg"
# Tapeti.Flow
- cmd: dotnet pack -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg --output output Tapeti.Flow\Tapeti.Flow.csproj /p:Configuration=Release /p:Version=%GitVersion_NuGetVersion%
- cmd: appveyor PushArtifact "output\Tapeti.Flow.%GitVersion_NuGetVersion%.nupkg"
- cmd: appveyor PushArtifact "output\Tapeti.Flow.%GitVersion_NuGetVersion%.snupkg"
# Tapeti.Flow.SQL
- cmd: dotnet pack -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg --output output Tapeti.Flow.SQL\Tapeti.Flow.SQL.csproj /p:Configuration=Release /p:Version=%GitVersion_NuGetVersion%
- cmd: appveyor PushArtifact "output\Tapeti.Flow.SQL.%GitVersion_NuGetVersion%.nupkg"
- cmd: appveyor PushArtifact "output\Tapeti.Flow.SQL.%GitVersion_NuGetVersion%.snupkg"
# Tapeti.Transient
- cmd: dotnet pack -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg --output output Tapeti.Transient\Tapeti.Transient.csproj /p:Configuration=Release /p:Version=%GitVersion_NuGetVersion%
- cmd: appveyor PushArtifact "output\Tapeti.Transient.%GitVersion_NuGetVersion%.nupkg"
- cmd: appveyor PushArtifact "output\Tapeti.Transient.%GitVersion_NuGetVersion%.snupkg"
# Tapeti.Serilog
- cmd: dotnet pack -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg --output output Tapeti.Serilog\Tapeti.Serilog.csproj /p:Configuration=Release /p:Version=%GitVersion_NuGetVersion%
- cmd: appveyor PushArtifact "output\Tapeti.Serilog.%GitVersion_NuGetVersion%.nupkg"
- cmd: appveyor PushArtifact "output\Tapeti.Serilog.%GitVersion_NuGetVersion%.snupkg"
# Tapeti.SimpleInjector
- cmd: dotnet pack -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg --output output Tapeti.SimpleInjector\Tapeti.SimpleInjector.csproj /p:Configuration=Release /p:Version=%GitVersion_NuGetVersion%
- cmd: appveyor PushArtifact "output\Tapeti.SimpleInjector.%GitVersion_NuGetVersion%.nupkg"
- cmd: appveyor PushArtifact "output\Tapeti.SimpleInjector.%GitVersion_NuGetVersion%.snupkg"
# Tapeti.Autofac
- cmd: dotnet pack -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg --output output Tapeti.Autofac\Tapeti.Autofac.csproj /p:Configuration=Release /p:Version=%GitVersion_NuGetVersion%
- cmd: appveyor PushArtifact "output\Tapeti.Autofac.%GitVersion_NuGetVersion%.nupkg"
- cmd: appveyor PushArtifact "output\Tapeti.Autofac.%GitVersion_NuGetVersion%.snupkg"
# Tapeti.CastleWindsor
- cmd: dotnet pack -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg --output output Tapeti.CastleWindsor\Tapeti.CastleWindsor.csproj /p:Configuration=Release /p:Version=%GitVersion_NuGetVersion%
- cmd: appveyor PushArtifact "output\Tapeti.CastleWindsor.%GitVersion_NuGetVersion%.nupkg"
- cmd: appveyor PushArtifact "output\Tapeti.CastleWindsor.%GitVersion_NuGetVersion%.snupkg"
# Tapeti.Ninject
- cmd: dotnet pack -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg --output output Tapeti.Ninject\Tapeti.Ninject.csproj /p:Configuration=Release /p:Version=%GitVersion_NuGetVersion%
- cmd: appveyor PushArtifact "output\Tapeti.Ninject.%GitVersion_NuGetVersion%.nupkg"
- cmd: appveyor PushArtifact "output\Tapeti.Ninject.%GitVersion_NuGetVersion%.snupkg"
# Tapeti.UnityContainer
- cmd: dotnet pack -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg --output output Tapeti.UnityContainer\Tapeti.UnityContainer.csproj /p:Configuration=Release /p:Version=%GitVersion_NuGetVersion%
- cmd: appveyor PushArtifact "output\Tapeti.UnityContainer.%GitVersion_NuGetVersion%.nupkg"
- cmd: appveyor PushArtifact "output\Tapeti.UnityContainer.%GitVersion_NuGetVersion%.snupkg"
# Create Tapeti.Cmd release
- cmd: dotnet publish -c Release -r win-x64 --self-contained=true -o publish\x64\selfcontained Tapeti.Cmd\Tapeti.Cmd.csproj
- cmd: dotnet publish -c Release -r win-x64 --self-contained=false -o publish\x64 Tapeti.Cmd\Tapeti.Cmd.csproj
- cmd: copy publish\x64\selfcontained\Tapeti.Cmd.exe publish\x64
- cmd: rmdir /s /q publish\x64\selfcontained
- cmd: 7z a output\Tapeti.Cmd-x64-%GitVersion_NuGetVersion%.zip %APPVEYOR_BUILD_FOLDER%\publish\x64\*
# Push artifacts
- ps: Get-ChildItem output\*.nupkg | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
- ps: Get-ChildItem output\*.snupkg | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
- ps: Get-ChildItem output\*.zip | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
build:
project: Tapeti.sln
@ -73,9 +45,18 @@ configuration:
- Release
deploy:
provider: NuGet
api_key:
secure: 3WCSZAzan66vEmHZ1q3XzfOfucuAQiA+SiCDChO/gswbxfIXUpiM1eMNASDa3qWH
- provider: NuGet
api_key:
secure: 3WCSZAzan66vEmHZ1q3XzfOfucuAQiA+SiCDChO/gswbxfIXUpiM1eMNASDa3qWH
skip_symbols: false
artifact: /.*(\.|\.s)nupkg/
skip_symbols: false
artifact: /.*(\.|\.s)nupkg/
- provider: GitHub
auth_token:
secure: dWOConKg3VTPvd9DmWOOKiX1SJCalaqKInuk9GlKQOZX2s+Bia49J7q+AHO8wFj7
artifact: /output\\Tapeti.Cmd-.*\.exe/
draft: false
prerelease: false
on:
branch: master
APPVEYOR_REPO_TAG: true