資源簡介
rabbitmq封裝,采用連接池,頻道也是采用連接池。減少頻繁連接造成的資源消耗。如果代碼有誤的地方請指出。
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?System.Threading;
using?System.Threading.Tasks;
using?RabbitMQ.Client;
namespace?MQCore
{
????internal?class?ConnectionInfo?:?IConnectionInfo
????{
????????IConnection?connection;
????????ChannelPool?channelPool;
????????object?_lock?=?new?object();
????????public?ConnectionInfo(IConnection?connection?int?capacity)
????????{
????????????this.connection?=?connection;
????????????channelPool?=?new?ChannelPool(capacity);
????????}
????????public?int?createChannelNum?{?get?{?return?channelPool?==?null???0?:?channelPool.createChannelNum;?}?}
????????///?
????????///?檢查是否允許釋放
????????///?
????????///?
????????public?bool?CheckCanFree()
????????{
????????????channelPool.TimeFree();
????????????return?channelPool.Count?==?0;
????????}
????????///?
????????///?釋放
????????///?
????????public?void?Free()
????????{
????????????connection?=?null;
????????????channelPool?=?null;
????????}
????????public?IMQChannel?CreateModel()
????????{
????????????lock?(_lock)
????????????{
????????????????return?channelPool.Pop(()=>?{
????????????????????channelPool.Push(new?MQChannel(channelPool?connection.CreateModel())?true);
????????????????});
????????????}
????????}
????????public?void?Dispose()
????????{
????????}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????85798??2019-08-20?15:44??MQ\.vs\config\applicationhost.config
????..A..H.????101888??2019-08-23?16:45??MQ\.vs\MQ\v15\.suo
?????文件???????1588??2019-08-21?10:48??MQ\MQ.sln
?????文件?????170288??2015-12-01?14:31??MQ\MQCore\bin\Debug\Microsoft.Diagnostics.Tracing.EventSource.dll
?????文件??????19456??2019-08-23?16:42??MQ\MQCore\bin\Debug\MQCore.dll
?????文件??????77312??2019-08-23?16:42??MQ\MQCore\bin\Debug\MQCore.pdb
?????文件?????276480??2018-06-18?15:49??MQ\MQCore\bin\Debug\RabbitMQ.Client.dll
?????文件???????1463??2019-08-23?15:23??MQ\MQCore\ConnectionInfo.cs
?????文件????????644??2019-08-23?15:15??MQ\MQCore\interface\IConnectionInfo.cs
?????文件????????368??2019-08-23?11:05??MQ\MQCore\interface\IMQChannel.cs
?????文件????????855??2019-08-22?17:23??MQ\MQCore\interface\IMQManage.cs
?????文件????????962??2019-08-20?19:09??MQ\MQCore\interface\IMQManageConfig.cs
?????文件????????646??2019-08-23?11:06??MQ\MQCore\MQChannel.cs
?????文件???????3123??2019-08-22?18:00??MQ\MQCore\MQCore.csproj
?????文件???????1709??2019-08-23?16:42??MQ\MQCore\MQManage.cs
?????文件???????1024??2019-08-20?19:09??MQ\MQCore\MQManageConfig.cs
?????文件???????2143??2019-08-22?11:41??MQ\MQCore\msg\Message.cs
?????文件???????8221??2019-08-22?17:54??MQ\MQCore\msg\RabbitMqDelayPublisher.cs
?????文件???????5518??2019-08-22?17:54??MQ\MQCore\msg\RabbitMqListener.cs
?????文件???????6554??2019-08-22?18:15??MQ\MQCore\msg\RabbitMqPublisher.cs
?????文件???????3626??2019-08-22?17:58??MQ\MQCore\msg\RabbitMqQuery.cs
?????文件??????12510??2019-08-22?17:59??MQ\MQCore\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件??????????0??2019-08-23?16:42??MQ\MQCore\obj\Debug\MQCore.csproj.CopyComplete
?????文件?????????42??2019-08-23?15:23??MQ\MQCore\obj\Debug\MQCore.csproj.CoreCompileInputs.cache
?????文件???????1304??2019-08-23?16:41??MQ\MQCore\obj\Debug\MQCore.csproj.FileListAbsolute.txt
?????文件???????8424??2019-08-23?16:41??MQ\MQCore\obj\Debug\MQCore.csprojAssemblyReference.cache
?????文件??????19456??2019-08-23?16:42??MQ\MQCore\obj\Debug\MQCore.dll
?????文件??????77312??2019-08-23?16:42??MQ\MQCore\obj\Debug\MQCore.pdb
?????文件??????????0??2019-08-20?19:03??MQ\MQCore\obj\Debug\MQManage.csproj.CopyComplete
?????文件?????????42??2019-08-20?19:03??MQ\MQCore\obj\Debug\MQManage.csproj.CoreCompileInputs.cache
............此處省略168個文件信息
評論
共有 條評論