Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/withlin/CommonX

基础框架
https://github.com/withlin/CommonX

autofac esb kafka log4net mapster masstransit quartz rabbitmq redis zookeeper

Last synced: 2 days ago
JSON representation

基础框架

Awesome Lists containing this project

README

        

# CommonX

## Getting Started
```C#
namespace ServiceBus.TestPublish.NetCore
{
using CommonX.Components;
using CommonX.Configurations;
using CommonX.Logging;
using System;
using System.Reflection;
using CommonX.ServiceBus.MassTransit.Configuration;
using CommonX.ServiceBus;
using CommonX.Log4Net;
using CommonX.RabbitMQ;
using CommonX.Kafka;
using CommonX.EventBus.Events;
using CommonX.EventBus.Abstractions;
using Confluent.Kafka;
using System.Threading.Tasks;
using System.Collections.Generic;
using CommonX.Quartz;
using CommonX.Cache.Redis;

public class RequestIntegrationEvent : IntegrationEvent
{
public string Message { get; set; }
}
public class RequestIntegrationEventHandler : IIntegrationEventHandler
{
public async Task Handle(RequestIntegrationEvent @event)
{
Console.WriteLine(@event.Id);
Console.WriteLine(@event.CreationDate);
Console.WriteLine(@event.Message);
Console.WriteLine(@event.Id);
await Task.FromResult(0);
}
}

class Program
{
private static IBus _bus;
private static ILogger _logger;
private static IConnectionPool _conn;
private static IConsumerClientFactory factory;
private static IKafkaPersisterConnection _consumerClient;
private static void HandlerMessage(Message msg)
{
Console.WriteLine($"消息的值为{msg.Value}");
}
static void Main(string[] args)
{
Setup();
Console.WriteLine();
List topics = new List();
topics.Add("test");
_consumerClient.Consume(topics, HandlerMessage);

_bus.Send("ServiceBus.TestPublish.NetCore", new RequestIntegrationEvent() { Message = "Masstransit test Succees!" });
_logger.Info("ServiceBus Logs test!!");
Console.WriteLine("Masstransit test Succees!");
Console.ReadKey();
}

public static void Setup()
{
var assambly = Assembly.GetAssembly(typeof(Program));
var config = Configuration.Create()
.UseAutofac()
.RegisterCommonComponents()
.UseLog4Net()
.UseJsonNet()
.UseQuartz(new Assembly[] { assambly })
.UseRabbitMQ(x=>
{
x.HostName = "localhost";
x.Port = 5067;
x.VirtualHost = "/";
x.UserName = "guest";
x.Password = "guest";
x.AutomaticRecoveryEnabled = true;
x.RequestedConnectionTimeout = 20000;
})
.UseRedisCache()
.UseMassTransit(new Assembly[] { assambly })
.UseKafka("");

using (var scope = ObjectContainer.Current.BeginLifetimeScope())
{
_logger = scope.Resolve().Create(typeof(Program).Name);
_bus = scope.Resolve();
_conn = scope.Resolve();
factory = scope.Resolve();
_consumerClient = scope.Resolve();
}
}
}
}

```