Skip to content

Commit b5f548d

Browse files
lukeabsentlahma
authored andcommitted
NMS 2.0
1 parent 7b163f0 commit b5f548d

39 files changed

+5016
-209
lines changed

examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Common/Spring.NmsQuickStart.Common.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<TargetFramework>$(TargetFullFrameworkVersion)</TargetFramework>
44
</PropertyGroup>
55
<ItemGroup>
6-
<PackageReference Include="Apache.NMS" Version="1.8.0" />
6+
<PackageReference Include="Apache.NMS" Version="2.0.0" />
77
<PackageReference Include="Apache.NMS.ActiveMQ" Version="1.7.2" />
88
</ItemGroup>
99
<ItemGroup>

src/Spring/Spring.Core/Threading/ThreadStaticStorage.cs

+37-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
1+
#region License
2+
// /*
3+
// * Copyright 2022 the original author or authors.
4+
// *
5+
// * Licensed under the Apache License, Version 2.0 (the "License");
6+
// * you may not use this file except in compliance with the License.
7+
// * You may obtain a copy of the License at
8+
// *
9+
// * http://www.apache.org/licenses/LICENSE-2.0
10+
// *
11+
// * Unless required by applicable law or agreed to in writing, software
12+
// * distributed under the License is distributed on an "AS IS" BASIS,
13+
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// * See the License for the specific language governing permissions and
15+
// * limitations under the License.
16+
// */
17+
#endregion
18+
119
using System.Collections;
20+
using System.Threading;
221

322
namespace Spring.Threading
423
{
@@ -9,14 +28,29 @@ namespace Spring.Threading
928
public class ThreadStaticStorage : IThreadStorage
1029
{
1130
[ThreadStatic]
12-
private static Hashtable data;
31+
private static Hashtable _dataThreadStatic;
32+
// AsyncLocal for it to work in async NMS lib
33+
private static AsyncLocal<Hashtable> _dataAsyncLocal = new AsyncLocal<Hashtable>();
34+
35+
/// <summary>
36+
/// Allows to switch how context is being held, if true, then it will use AsyncLocal
37+
/// </summary>
38+
public static bool UseAsyncLocal { get; set; } = false;
1339

1440
private static Hashtable Data
1541
{
1642
get
1743
{
18-
if (data == null) data = new Hashtable();
19-
return data;
44+
if (UseAsyncLocal)
45+
{
46+
if (_dataAsyncLocal.Value == null) _dataAsyncLocal.Value = new Hashtable();
47+
return _dataAsyncLocal.Value;
48+
}
49+
else
50+
{
51+
if (_dataThreadStatic == null) _dataThreadStatic = new Hashtable();
52+
return _dataThreadStatic;
53+
}
2054
}
2155
}
2256

src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/CachedMessageConsumer .cs

+26-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,16 @@ public IMessageConsumer Target
5151
get { return target; }
5252
}
5353

54+
public string MessageSelector
55+
{
56+
get
57+
{
58+
return target.MessageSelector;
59+
}
60+
}
61+
5462
/// <summary>
55-
/// Register for message events.
63+
/// Register for message events.
5664
/// </summary>
5765
public event MessageListener Listener
5866
{
@@ -75,6 +83,11 @@ public IMessage Receive()
7583
return this.target.Receive();
7684
}
7785

86+
public Task<IMessage> ReceiveAsync()
87+
{
88+
return this.target.ReceiveAsync();
89+
}
90+
7891
/// <summary>
7992
/// Receives the next message that arrives within the specified timeout interval.
8093
/// </summary>
@@ -85,6 +98,11 @@ public IMessage Receive(TimeSpan timeout)
8598
return this.target.Receive(timeout);
8699
}
87100

101+
public Task<IMessage> ReceiveAsync(TimeSpan timeout)
102+
{
103+
return this.target.ReceiveAsync(timeout);
104+
}
105+
88106
/// <summary>
89107
/// Receives the next message if one is immediately available.
90108
/// </summary>
@@ -102,6 +120,12 @@ public void Close()
102120
// It's a cached MessageConsumer...
103121
}
104122

123+
public Task CloseAsync()
124+
{
125+
// It's a cached MessageConsumer...
126+
return Task.FromResult(true);
127+
}
128+
105129
/// <summary>
106130
/// A Delegate that is called each time a Message is dispatched to allow the client to do
107131
/// any necessary transformations on the received message before it is delivered.
@@ -131,4 +155,4 @@ public override string ToString()
131155
return "Cached NMS MessageConsumer: " + this.target;
132156
}
133157
}
134-
}
158+
}

src/Spring/Spring.Messaging.Nms/Messaging/Nms/Connections/CachedMessageProducer.cs

+75-2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,32 @@ public void Send(IDestination destination, IMessage message, MsgDeliveryMode del
111111
target.Send(destination, message, deliveryMode, priority, timeToLive);
112112
}
113113

114+
public TimeSpan DeliveryDelay
115+
{
116+
get { return target.DeliveryDelay; }
117+
set { target.DeliveryDelay = value; }
118+
}
119+
120+
public Task SendAsync(IMessage message)
121+
{
122+
return target.SendAsync(message);
123+
}
124+
125+
public Task SendAsync(IMessage message, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive)
126+
{
127+
return target.SendAsync(message, deliveryMode, priority, timeToLive);
128+
}
129+
130+
public Task SendAsync(IDestination destination, IMessage message)
131+
{
132+
return target.SendAsync(destination, message);
133+
}
134+
135+
public Task SendAsync(IDestination destination, IMessage message, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive)
136+
{
137+
return target.SendAsync(destination, message, deliveryMode, priority, timeToLive);
138+
}
139+
114140
#region Odd Message Creationg Methods on IMessageProducer - not in-line with JMS APIs.
115141
/// <summary>
116142
/// Creates the message.
@@ -121,6 +147,11 @@ public IMessage CreateMessage()
121147
return target.CreateMessage();
122148
}
123149

150+
public Task<IMessage> CreateMessageAsync()
151+
{
152+
return target.CreateMessageAsync();
153+
}
154+
124155
/// <summary>
125156
/// Creates the text message.
126157
/// </summary>
@@ -130,6 +161,11 @@ public ITextMessage CreateTextMessage()
130161
return target.CreateTextMessage();
131162
}
132163

164+
public Task<ITextMessage> CreateTextMessageAsync()
165+
{
166+
return target.CreateTextMessageAsync();
167+
}
168+
133169
/// <summary>
134170
/// Creates the text message.
135171
/// </summary>
@@ -140,6 +176,11 @@ public ITextMessage CreateTextMessage(string text)
140176
return target.CreateTextMessage(text);
141177
}
142178

179+
public Task<ITextMessage> CreateTextMessageAsync(string text)
180+
{
181+
return target.CreateTextMessageAsync(text);
182+
}
183+
143184
/// <summary>
144185
/// Creates the map message.
145186
/// </summary>
@@ -149,6 +190,11 @@ public IMapMessage CreateMapMessage()
149190
return target.CreateMapMessage();
150191
}
151192

193+
public Task<IMapMessage> CreateMapMessageAsync()
194+
{
195+
return target.CreateMapMessageAsync();
196+
}
197+
152198
/// <summary>
153199
/// Creates the object message.
154200
/// </summary>
@@ -159,6 +205,11 @@ public IObjectMessage CreateObjectMessage(object body)
159205
return target.CreateObjectMessage(body);
160206
}
161207

208+
public Task<IObjectMessage> CreateObjectMessageAsync(object body)
209+
{
210+
return target.CreateObjectMessageAsync(body);
211+
}
212+
162213
/// <summary>
163214
/// Creates the bytes message.
164215
/// </summary>
@@ -168,6 +219,11 @@ public IBytesMessage CreateBytesMessage()
168219
return target.CreateBytesMessage();
169220
}
170221

222+
public Task<IBytesMessage> CreateBytesMessageAsync()
223+
{
224+
return target.CreateBytesMessageAsync();
225+
}
226+
171227
/// <summary>
172228
/// Creates the bytes message.
173229
/// </summary>
@@ -178,6 +234,11 @@ public IBytesMessage CreateBytesMessage(byte[] body)
178234
return target.CreateBytesMessage(body);
179235
}
180236

237+
public Task<IBytesMessage> CreateBytesMessageAsync(byte[] body)
238+
{
239+
return target.CreateBytesMessageAsync(body);
240+
}
241+
181242
/// <summary>
182243
/// Creates the stream message.
183244
/// </summary>
@@ -187,6 +248,12 @@ public IStreamMessage CreateStreamMessage()
187248
return target.CreateStreamMessage();
188249
}
189250

251+
public Task<IStreamMessage> CreateStreamMessageAsync()
252+
{
253+
return target.CreateStreamMessageAsync();
254+
}
255+
256+
190257
/// <summary>
191258
/// A delegate that is called each time a Message is sent from this Producer which allows
192259
/// the application to perform any needed transformations on the Message before it is sent.
@@ -302,7 +369,13 @@ public void Close()
302369
originalDisableMessageTimestamp = null;
303370
}
304371
}
305-
372+
373+
public Task CloseAsync()
374+
{
375+
Close();
376+
return Task.FromResult(true);
377+
}
378+
306379
/// <summary>
307380
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
308381
/// </summary>
@@ -321,4 +394,4 @@ public override string ToString()
321394
return "Cached NMS MessageProducer: " + this.target;
322395
}
323396
}
324-
}
397+
}

0 commit comments

Comments
 (0)