本文整理汇总了C#中Conventions类的典型用法代码示例。如果您正苦于以下问题:C# Conventions类的具体用法?C# Conventions怎么用?C# Conventions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Conventions类属于命名空间,在下文中一共展示了Conventions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateBus
public static IBus CreateBus()
{
var connectionFactory = new InMemoryConnectionFactory();
var serializer = new JsonSerializer();
var logger = new ConsoleLogger();
var conventions = new Conventions();
var consumerErrorStrategy = new DefaultConsumerErrorStrategy(connectionFactory, serializer, logger, conventions);
var advancedBus = new RabbitAdvancedBus(
new ConnectionConfiguration(),
connectionFactory,
TypeNameSerializer.Serialize,
serializer,
new QueueingConsumerFactory(logger, consumerErrorStrategy),
logger,
CorrelationIdGenerator.GetCorrelationId,
conventions);
return new RabbitBus(
TypeNameSerializer.Serialize,
logger,
conventions,
advancedBus);
}
示例2: AssertIsValidForSend
public static void AssertIsValidForSend(Type messageType, Conventions conventions)
{
if (conventions.IsEventType(messageType))
{
throw new InvalidOperationException("Events can have multiple recipient so they should be published");
}
}
示例3: SetUp
public void SetUp()
{
var connectionFactory = new ConnectionFactoryWrapper(new ConnectionFactory
{
HostName = "localhost",
VirtualHost = "/",
UserName = "guest",
Password = "guest"
});
var serializer = new JsonSerializer();
var logger = new ConsoleLogger();
var consumerErrorStrategy = new DefaultConsumerErrorStrategy(connectionFactory, serializer, logger);
var conventions = new Conventions();
advancedBus = new RabbitAdvancedBus(
connectionFactory,
TypeNameSerializer.Serialize,
serializer,
new QueueingConsumerFactory(logger, consumerErrorStrategy),
logger,
CorrelationIdGenerator.GetCorrelationId,
conventions);
while (!advancedBus.IsConnected)
{
Thread.Sleep(10);
}
}
示例4: AssertIsValidForReply
public static void AssertIsValidForReply(Type messageType, Conventions conventions)
{
if (conventions.IsCommandType(messageType) || conventions.IsEventType(messageType))
{
throw new InvalidOperationException("Reply is neither supported for Commands nor Events. Commands should be sent to their logical owner using bus.Send and bus. Events should be Published with bus.Publish.");
}
}
示例5: SetUp
public void SetUp()
{
var mockModel = new MockModel
{
ExchangeDeclareAction = (exchangeName, type, durable, autoDelete, arguments) => createdExchangeName = exchangeName,
BasicPublishAction = (exchangeName, topic, properties, messageBody) =>
{
publishedToExchangeName = exchangeName;
publishedToTopic = topic;
}
};
var customConventions = new Conventions
{
ExchangeNamingConvention = x => "CustomExchangeNamingConvention",
QueueNamingConvention = (x, y) => "CustomQueueNamingConvention",
TopicNamingConvention = x => "CustomTopicNamingConvention"
};
CreateBus(customConventions, mockModel);
using (var publishChannel = bus.OpenPublishChannel())
{
publishChannel.Publish(new TestMessage());
}
}
示例6: IsCommandType_should_return_false_for_NServiceBus_types
public void IsCommandType_should_return_false_for_NServiceBus_types()
{
var conventions = new Conventions
{
IsCommandTypeAction = t => t.Assembly == typeof(Conventions).Assembly
};
Assert.IsFalse(conventions.IsCommandType(typeof(Conventions)));
}
示例7: AdvancedConfiguration
internal AdvancedConfiguration()
{
Conventions = new Conventions
{
new FindByPolicyNameConvention(),
new FindDefaultPolicyViolationHandlerByNameConvention()
};
SetDefaultResultsCacheLifecycle(Cache.DoNotCache);
}
示例8: GetMessageTypesHandledByThisEndpoint
static List<Type> GetMessageTypesHandledByThisEndpoint(MessageHandlerRegistry handlerRegistry, Conventions conventions, SubscribeSettings settings)
{
var messageTypesHandled = handlerRegistry.GetMessageTypes() //get all potential messages
.Where(t => !conventions.IsInSystemConventionList(t)) //never auto-subscribe system messages
.Where(t => !conventions.IsCommandType(t)) //commands should never be subscribed to
.Where(conventions.IsEventType) //only events unless the user asked for all messages
.Where(t => settings.AutoSubscribeSagas || handlerRegistry.GetHandlersFor(t).Any(handler => !typeof(Saga).IsAssignableFrom(handler.HandlerType))) //get messages with other handlers than sagas if needed
.ToList();
return messageTypesHandled;
}
示例9: CreateBus
private void CreateBus(Conventions conventions, IModel model)
{
bus = new RabbitBus(
x => TypeNameSerializer.Serialize(x.GetType()),
new JsonSerializer(),
new MockConsumerFactory(),
new MockConnectionFactory(new MockConnection(model)),
new MockLogger(),
CorrelationIdGenerator.GetCorrelationId,
conventions
);
}
示例10: AssertIsValidForPubSub
public static void AssertIsValidForPubSub(Type messageType, Conventions conventions)
{
if (conventions.IsCommandType(messageType))
{
throw new InvalidOperationException("Pub/Sub is not supported for Commands. They should be be sent direct to their logical owner.");
}
if (!conventions.IsEventType(messageType))
{
Log.Info("You are using a basic message to do pub/sub, consider implementing the more specific ICommand and IEvent interfaces to help NServiceBus to enforce messaging best practices for you.");
}
}
示例11: Apply
public void Apply(UnicastRoutingTable unicastRoutingTable, Conventions conventions)
{
var entries = new Dictionary<Type, RouteTableEntry>();
foreach (var source in routeSources.OrderBy(x => x.Priority)) //Higher priority routes sources override lower priority.
{
foreach (var route in source.GenerateRoutes(conventions))
{
entries[route.MessageType] = route;
}
}
unicastRoutingTable.AddOrReplaceRoutes("EndpointConfiguration", entries.Values.ToList());
}
示例12: Should_add_convention_for_predicate_to_instance
public void Should_add_convention_for_predicate_to_instance()
{
// Arrange
Func<PolicyResult, bool> expectedPredicate = x => true;
var conventions = new Conventions();
var expression = new ViolationHandlerExpression(new ViolationConfigurationExpression(conventions), expectedPredicate);
// Act
expression.IsHandledBy(() => new DefaultPolicyViolationHandler());
// Assert
Assert.That(conventions.Single().As<PredicateToPolicyViolationHandlerInstanceConvention<DefaultPolicyViolationHandler>>().Predicate, Is.EqualTo(expectedPredicate));
}
示例13: SetUp
public void SetUp()
{
typeNameSerializer = new TypeNameSerializer();
var customConventions = new Conventions(typeNameSerializer)
{
ExchangeNamingConvention = x => "CustomExchangeNamingConvention",
QueueNamingConvention = (x, y) => "CustomQueueNamingConvention",
TopicNamingConvention = x => "CustomTopicNamingConvention"
};
mockBuilder = new MockBuilder(x => x.Register<IConventions>(_ => customConventions));
mockBuilder.Bus.Publish(new TestMessage());
}
示例14: Should_return_metadata_for_a_mapped_type
public void Should_return_metadata_for_a_mapped_type()
{
var conventions = new Conventions();
conventions.IsMessageTypeAction = type => type == typeof(int);
var defaultMessageRegistry = new MessageMetadataRegistry(conventions);
defaultMessageRegistry.RegisterMessageTypesFoundIn(new List<Type> { typeof(int) });
var messageMetadata = defaultMessageRegistry.GetMessageMetadata(typeof(int));
Assert.AreEqual(typeof(int), messageMetadata.MessageType);
Assert.AreEqual(1, messageMetadata.MessageHierarchy.Count());
}
示例15: SetUp
public void SetUp()
{
var conventions = new Conventions(new TypeNameSerializer())
{
ConsumerTagConvention = () => consumerTag
};
mockBuilder = new MockBuilder(x => x
.Register<IConventions>(_ => conventions)
//.Register<IEasyNetQLogger>(_ => new ConsoleLogger())
);
mockBuilder.Bus.Subscribe<MyMessage>(subscriptionId, message => { });
}