|
28 | 28 | // *********************************************************************** |
29 | 29 | namespace RabbitExpress |
30 | 30 | { |
| 31 | + using Microsoft.Extensions.Options; |
31 | 32 | using MsgPack.Serialization; |
32 | 33 | using RabbitMQ.Client; |
33 | 34 | using RabbitMQ.Client.Events; |
@@ -209,14 +210,42 @@ private void RegisterQueues<TInterface>() |
209 | 210 | /// </summary> |
210 | 211 | /// <param name="connectionString">The connection string.</param> |
211 | 212 | public QueueClient(Uri connectionString) |
| 213 | + : this(new ConnectionFactory() { Uri = connectionString, DispatchConsumersAsync = true }) |
212 | 214 | { |
213 | 215 | var factory = new ConnectionFactory() |
214 | 216 | { |
215 | 217 | Uri = connectionString, |
216 | 218 | DispatchConsumersAsync = true |
217 | 219 | }; |
| 220 | + } |
218 | 221 |
|
219 | | - _connection = factory.CreateConnection(); |
| 222 | + /// <summary> |
| 223 | + /// Initializes a new instance of the <see cref="QueueClient{TSerializer}"/> class. |
| 224 | + /// </summary> |
| 225 | + /// <param name="config">The connection setting.</param> |
| 226 | + public QueueClient(IOptions<QueueConfig> config) |
| 227 | + : this(config.Value.ConnectionString) |
| 228 | + { |
| 229 | + _model.BasicQos(0, config.Value.PrefetchSize, false); |
| 230 | + } |
| 231 | + |
| 232 | + /// <summary> |
| 233 | + /// Initializes a new instance of the <see cref="QueueClient{TSerializer}"/> class. |
| 234 | + /// </summary> |
| 235 | + /// <param name="config">The connection setting.</param> |
| 236 | + public QueueClient(QueueConfig config) |
| 237 | + : this(config.ConnectionString) |
| 238 | + { |
| 239 | + _model.BasicQos(0, config.PrefetchSize, false); |
| 240 | + } |
| 241 | + |
| 242 | + /// <summary> |
| 243 | + /// Initializes a new instance of the <see cref="QueueClient{TSerializer}"/> class. |
| 244 | + /// </summary> |
| 245 | + /// <param name="connectionFactory">The connection factory used to create the connection.</param> |
| 246 | + public QueueClient(IConnectionFactory connectionFactory) |
| 247 | + { |
| 248 | + _connection = connectionFactory.CreateConnection(); |
220 | 249 | _model = _connection.CreateModel(); |
221 | 250 |
|
222 | 251 | _consumer = new AsyncEventingBasicConsumer(_model); |
|
0 commit comments