1 Star 7 Fork 4

MUSHR / Helpers2

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

Helpers.RabbitMqHelper-rabbitmq封装类(已应用到生产环境)

自动创建交换机,队列,并将交换机和队列绑定,可以更加专注于业务代码的编写,处理了生产者并发BasicPublish报505的问题

MqConfig config = new MqConfig()
{
    HostName = "xxx",
    Port = xxx,
    UserName = "xxx",
    Password = "xxx",
    ExchangeName = "xxx",
    vHost = "xxx",
    PrefetchCount = 1,
    AutoAck = false,
    IsDebug = false,
};
MqGlobleConfig.InitDefaultConnection(config);

MqChannelManager channelManager = new MqChannelManager();
//创建消费者
var receiveChannel = channelManager.CreateReceiveChannel("xxx", async x =>
{
    Log.Information($"receive => {x.Content}");
    x.BasicAck();//手动回答
});
//创建生产者
var producerChannel = channelManager.CreatePublishChannel("xxx");
//单个
producerChannel.Publish("xxx");
//批量
producerChannel.BatchPublish(Enumerable.Range(1, 10000).Select(x => "xxx"));
Thread.Sleep(-1);
producerChannel.Stop();

Helpers.DiHelper

主要用于控制台,方便di调用

Helpers.MongoHelper

//在配置文件添加节点mongo
public class MongoConfig
{
    public const string SectionName = "mongo";
    /// <summary>
    /// 数据库连接串
    /// </summary>
    [Required]
    public string Connection { get; set; }
    /// <summary>
    /// 数据库名称
    /// </summary>
    [Required]
    public string DatabaseName { get; set; }
    /// <summary>
    /// 仓储所在的程序集名称,非必填项,默认启动时会自动发现仓储类并注册
    /// </summary>
    public List<string> RepositoryAssemblyNames { get; set; }
}

//注册服务
services.AddMongoHelperz(Configuration);

//定义实体
public class SysParams : MongoEntity
{
    public string code { get; set; }
    public string value { get; set; }
}
//定义单例仓储,用于集合名称固定的
public class SysParamsRepository : MongoRepository<SysParams>
{

}
//定义多例仓储,用于集合名称不固定(分表)
public class SysParamsRepository : TransientMongoRepository<SysParams>
{
    public AliUserDataRepository(IMongoDatabase mongoDatabase) : base(mongoDatabase, "_xxxx")
    {
    }
    public override void SetCollectionName(Func<string> configure)
    {
        //编辑集合名称
        GetCollectionName = () => $"{configure()}{_collectionName}";
    }
}

Comments ( 0 )

Sign in for post a comment

About

通用帮助类.net core版,使用net standard2.0,部分帮助类已经升级成net standard2.1 spread retract
C#
MIT
Cancel

Releases

No release

Contributors

All

Activities

load more
can not load any more
C#
1
https://gitee.com/mushr/Helpers2.git
git@gitee.com:mushr/Helpers2.git
mushr
Helpers2
Helpers2
master

Search

102255 3a0e046c 1850385 102255 7aaa926c 1850385