Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
基础框架
- Host: GitHub
- URL: https://github.com/withlin/CommonX
- Owner: withlin
- Created: 2018-02-05T12:07:28.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-06-04T12:34:39.000Z (over 6 years ago)
- Last Synced: 2024-11-07T15:53:02.599Z (7 days ago)
- Topics: autofac, esb, kafka, log4net, mapster, masstransit, quartz, rabbitmq, redis, zookeeper
- Language: C#
- Homepage:
- Size: 16.2 MB
- Stars: 57
- Watchers: 7
- Forks: 21
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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();
}
}
}
}```