-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathActiveMqQueueTransactedMessageAdapter.cs
More file actions
71 lines (66 loc) · 2.11 KB
/
ActiveMqQueueTransactedMessageAdapter.cs
File metadata and controls
71 lines (66 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using Apache.NMS;
using Microsoft.Extensions.Logging;
using ViennaNET.Messaging.Exceptions;
using ViennaNET.Messaging.Messages;
namespace ViennaNET.Messaging.ActiveMQQueue
{
/// <summary>
/// Адаптер очереди ActiveMQ
/// </summary>
public class ActiveMqQueueTransactedMessageAdapter : ActiveMqQueueMessageAdapter, IMessageAdapterWithTransactions
{
private readonly ActiveMqQueueConfiguration _queueConfiguration;
/// <summary>
/// Адаптер с поддержкой транзакций, реализующий взаимодействие с очередью ActiveMQ
/// </summary>
/// <param name="connectionFactory">Фабрика подключений</param>
/// <param name="queueConfiguration">Параметры очереди</param>
/// <param name="logger">Сервис логирования</param>
public ActiveMqQueueTransactedMessageAdapter(IActiveMqConnectionFactory connectionFactory,
ActiveMqQueueConfiguration queueConfiguration,
ILogger logger)
: base(connectionFactory, queueConfiguration, logger)
{
_queueConfiguration = queueConfiguration;
}
/// <inheritdoc />
public void CommitIfTransacted(BaseMessage message)
{
try
{
if (_queueConfiguration.TransactionEnabled)
{
Session.Commit();
}
}
catch (NMSException ex)
{
throw new MessagingException(
ex,
$"Error committing message for queue {_queueConfiguration.Id}. See inner exception");
}
}
/// <inheritdoc />
public void RollbackIfTransacted()
{
try
{
if (_queueConfiguration.TransactionEnabled)
{
Session.Rollback();
}
}
catch (NMSException ex)
{
throw new MessagingException(
ex,
$"Error rolling back message for queue {_queueConfiguration.Id}. See inner exception");
}
}
/// <inheritdoc />
protected override ISession CreateSession(IConnection connection)
{
return connection.CreateSession(AcknowledgementMode.Transactional);
}
}
}