logstash-input-jms 3.0.6-java → 3.1.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,137 @@
1
+ <!--
2
+ Licensed to the Apache Software Foundation (ASF) under one or more
3
+ contributor license agreements. See the NOTICE file distributed with
4
+ this work for additional information regarding copyright ownership.
5
+ The ASF licenses this file to You under the Apache License, Version 2.0
6
+ (the "License"); you may not use this file except in compliance with
7
+ the License. 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
+ <!-- START SNIPPET: example -->
18
+ <beans
19
+ xmlns="http://www.springframework.org/schema/beans"
20
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
22
+ http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
23
+
24
+ <!-- Allows us to use system properties as variables in this configuration file -->
25
+ <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
26
+ <property name="locations">
27
+ <value>file:${activemq.conf}/credentials.properties</value>
28
+ </property>
29
+ </bean>
30
+
31
+ <!-- Allows accessing the server log -->
32
+ <bean id="logQuery" class="io.fabric8.insight.log.log4j.Log4jLogQuery"
33
+ lazy-init="false" scope="singleton"
34
+ init-method="start" destroy-method="stop">
35
+ </bean>
36
+
37
+ <!--
38
+ The <broker> element is used to configure the ActiveMQ broker.
39
+ -->
40
+ <broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}">
41
+
42
+ <destinationPolicy>
43
+ <policyMap>
44
+ <policyEntries>
45
+ <policyEntry topic=">" >
46
+ <!-- The constantPendingMessageLimitStrategy is used to prevent
47
+ slow topic consumers to block producers and affect other consumers
48
+ by limiting the number of messages that are retained
49
+ For more information, see:
50
+
51
+ http://activemq.apache.org/slow-consumer-handling.html
52
+
53
+ -->
54
+ <pendingMessageLimitStrategy>
55
+ <constantPendingMessageLimitStrategy limit="1000"/>
56
+ </pendingMessageLimitStrategy>
57
+ </policyEntry>
58
+ </policyEntries>
59
+ </policyMap>
60
+ </destinationPolicy>
61
+
62
+
63
+ <!--
64
+ The managementContext is used to configure how ActiveMQ is exposed in
65
+ JMX. By default, ActiveMQ uses the MBean server that is started by
66
+ the JVM. For more information, see:
67
+
68
+ http://activemq.apache.org/jmx.html
69
+ -->
70
+ <managementContext>
71
+ <managementContext createConnector="false"/>
72
+ </managementContext>
73
+
74
+ <!--
75
+ Configure message persistence for the broker. The default persistence
76
+ mechanism is the KahaDB store (identified by the kahaDB tag).
77
+ For more information, see:
78
+
79
+ http://activemq.apache.org/persistence.html
80
+ -->
81
+ <persistenceAdapter>
82
+ <kahaDB directory="${activemq.data}/kahadb"/>
83
+ </persistenceAdapter>
84
+
85
+
86
+ <!--
87
+ The systemUsage controls the maximum amount of space the broker will
88
+ use before disabling caching and/or slowing down producers. For more information, see:
89
+ http://activemq.apache.org/producer-flow-control.html
90
+ -->
91
+ <systemUsage>
92
+ <systemUsage>
93
+ <memoryUsage>
94
+ <memoryUsage percentOfJvmHeap="70" />
95
+ </memoryUsage>
96
+ <storeUsage>
97
+ <storeUsage limit="100 gb"/>
98
+ </storeUsage>
99
+ <tempUsage>
100
+ <tempUsage limit="50 gb"/>
101
+ </tempUsage>
102
+ </systemUsage>
103
+ </systemUsage>
104
+
105
+ <sslContext>
106
+ <sslContext
107
+ keyStore="spec/inputs/fixtures/keystore.jks" keyStorePassword="changeit"
108
+ trustStore="spec/inputs/fixtures/keystore.jks" trustStorePassword="changeit"/>
109
+ </sslContext>
110
+ <!--
111
+ The transport connectors expose ActiveMQ over a given protocol to
112
+ clients and other brokers. For more information, see:
113
+
114
+ http://activemq.apache.org/configuring-transports.html
115
+ -->
116
+ <transportConnectors>
117
+ <!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
118
+ <transportConnector name="ssl_openwire" uri="ssl://0.0.0.0:61617?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
119
+ </transportConnectors>
120
+
121
+ <!-- destroy the spring context on shutdown to stop jetty -->
122
+ <shutdownHooks>
123
+ <bean xmlns="http://www.springframework.org/schema/beans" class="org.apache.activemq.hooks.SpringContextHook" />
124
+ </shutdownHooks>
125
+
126
+ </broker>
127
+
128
+ <!--
129
+ Enable web consoles, REST and Ajax APIs and demos
130
+ The web consoles requires by default login, you can disable this in the jetty.xml file
131
+
132
+ Take a look at ${ACTIVEMQ_HOME}/conf/jetty.xml for more details
133
+ -->
134
+ <import resource="jetty.xml"/>
135
+
136
+ </beans>
137
+ <!-- END SNIPPET: example -->
@@ -0,0 +1,14 @@
1
+ ---
2
+ activemq:
3
+ :broker_url: tcp://localhost:61616
4
+ :username: username
5
+ :password: the_password
6
+ :factory: org.apache.activemq.ActiveMQConnectionFactory
7
+ :require_jars:
8
+ - activemq-all.jar
9
+
10
+ activemq_tls:
11
+ :broker_url: ssl://localhost:61617
12
+ :factory: org.apache.activemq.ActiveMQConnectionFactory
13
+ :require_jars:
14
+ - activemq-all.jar
@@ -0,0 +1,22 @@
1
+ ---
2
+ solace:
3
+ :jndi_name: /jms/cf/default
4
+ :jndi_context:
5
+ java.naming.factory.initial: com.solacesystems.jndi.SolJNDIInitialContextFactory
6
+ java.naming.security.principal: username
7
+ java.naming.provider.url: tcp://localhost:20608
8
+ java.naming.security.credentials: password
9
+ :require_jars:
10
+ - commons-lang-2.6.jar
11
+ - sol-jms-10.5.0.jar
12
+ - geronimo-jms_1.1_spec-1.1.1.jar
13
+ - commons-lang-2.6.jar
14
+
15
+ activemq:
16
+ :username: user
17
+ :password: password
18
+ :broker_url: tcp://localhost:61616
19
+ :runner: consumer
20
+ :factory: org.apache.activemq.ActiveMQConnectionFactory
21
+ :require_jars:
22
+ - activemq-all-5.15.8.jar
@@ -0,0 +1,284 @@
1
+ require_relative '../spec_helper'
2
+ require 'logstash/inputs/jms'
3
+ require 'jms'
4
+ require 'json'
5
+ require 'securerandom'
6
+
7
+
8
+
9
+ shared_examples_for "a JMS input" do
10
+ context 'when inputting messages' do
11
+ let (:destination) { "#{pub_sub ? 'topic' : 'queue'}://#{queue_name}"}
12
+ let (:queue) { [] }
13
+
14
+ context 'when the message is a text message' do
15
+ let(:message) { "Hello There" }
16
+
17
+ context 'when properties are skipped' do
18
+ let (:jms_config) { super.merge({'skip_properties' => ['this', 'that']})}
19
+
20
+ it 'should skip the specified property and process other properties, headers and the message' do
21
+ send_message do |session|
22
+ msg = session.message(message)
23
+ msg.set_string_property('this', 'this_prop')
24
+ msg.set_string_property('that', 'that_prop')
25
+ msg.set_string_property('the_other', 'the_other_prop')
26
+ msg
27
+ end
28
+ expect(queue.first.get('message')).to eql (message)
29
+ expect(queue.first.get('jms_destination')).to_not be_nil
30
+ expect(queue.first.get('jms_timestamp')).to_not be_nil
31
+ expect(queue.first.get('this')).to be_nil
32
+ expect(queue.first.get('that')).to be_nil
33
+ expect(queue.first.get('the_other')).to eql('the_other_prop')
34
+ end
35
+ end
36
+
37
+ context 'when using message selectors' do
38
+ let (:jms_config) { super.merge({'selector' => selector }) }
39
+
40
+ context 'with multiple selector query parameter' do
41
+ let (:selector) { "this = 3 OR this = 4" }
42
+
43
+ it 'process messages that conform to the message selector' do
44
+ send_message do |session|
45
+ msg = session.message(message)
46
+ msg.set_string_property('that', 'that_prop')
47
+ msg.set_int_property('this', 4)
48
+ msg
49
+ end
50
+ expect(queue.first.get('message')).to eql (message)
51
+ expect(queue.first.get('this')).to eql(4)
52
+ expect(queue.first.get('that')).to eql('that_prop')
53
+ end
54
+
55
+ it 'does not process messages that do not conform to the message selector' do
56
+ send_message do |session|
57
+ msg = session.message(message)
58
+ msg.set_string_property('this', 'that_prop')
59
+ msg.set_string_property('that', 'this_prop')
60
+ msg
61
+ end
62
+ expect(queue.size).to be 0
63
+ end
64
+ end
65
+
66
+ context 'with an integer property' do
67
+ let (:selector) { "this < 4" }
68
+
69
+ it 'process messages that conform to the message selector' do
70
+ send_message do |session|
71
+ msg = session.message(message)
72
+ msg.set_string_property('that', 'that_prop')
73
+ msg.set_int_property('this', 3)
74
+ msg
75
+ end
76
+ expect(queue.first.get('message')).to eql (message)
77
+ expect(queue.first.get('this')).to eql(3)
78
+ expect(queue.first.get('that')).to eql('that_prop')
79
+ end
80
+
81
+ it 'does not process messages that do not conform to the message selector' do
82
+ send_message do |session|
83
+ msg = session.message(message)
84
+ msg.set_string_property('this', 'that_prop')
85
+ msg.set_string_property('that', 'this_prop')
86
+ msg
87
+ end
88
+ expect(queue.size).to be 0
89
+ end
90
+ end
91
+
92
+ context 'with a float property' do
93
+ let (:selector) { "this < 3.3" }
94
+
95
+ it 'process messages that conform to the message selector' do
96
+ send_message do |session|
97
+ msg = session.message(message)
98
+ msg.set_string_property('that', 'that_prop')
99
+ msg.set_float_property('this', 3.1)
100
+ msg
101
+ end
102
+ expect(queue.first.get('message')).to eql(message)
103
+ expect(queue.first.get('this')).to be_within(0.001).of(3.1)
104
+ expect(queue.first.get('that')).to eql('that_prop')
105
+ end
106
+
107
+ it 'does not process messages that do not conform to the message selector' do
108
+ send_message do |session|
109
+ msg = session.message(message)
110
+ msg.set_string_property('this', 'that_prop')
111
+ msg.set_string_property('that', 'this_prop')
112
+ msg
113
+ end
114
+ expect(queue.size).to be 0
115
+ end
116
+ end
117
+
118
+
119
+ context 'with a string property' do
120
+ let (:selector) { "this = 'this_prop'" }
121
+
122
+ it 'process messages that conform to the message selector' do
123
+ send_message do |session|
124
+ msg = session.message(message)
125
+ msg.set_string_property('this', 'this_prop')
126
+ msg.set_string_property('that', 'that_prop')
127
+ msg
128
+ end
129
+ expect(queue.first.get('message')).to eql (message)
130
+ expect(queue.first.get('this')).to eql('this_prop')
131
+ expect(queue.first.get('that')).to eql('that_prop')
132
+ end
133
+
134
+ it 'does not process messages that do not conform to the message selector' do
135
+ send_message do |session|
136
+ msg = session.message(message)
137
+ msg.set_string_property('this', 'that_prop')
138
+ msg.set_string_property('that', 'this_prop')
139
+ msg
140
+ end
141
+ expect(queue.size).to be 0
142
+ end
143
+
144
+ end
145
+ end
146
+
147
+ context 'when headers are skipped' do
148
+ let (:jms_config) { super.merge({'skip_headers' => ['jms_destination', 'jms_reply_to']})}
149
+ it 'should skip the specified header and process other headers, properties and the message' do
150
+ send_message do |session|
151
+ msg = session.message(message)
152
+ msg.reply_to = session.create_destination(:topic_name => SecureRandom.hex(8))
153
+ msg.set_string_property('this', 'this_prop')
154
+ msg.set_string_property('that', 'that_prop')
155
+ msg.set_string_property('the_other', 'the_other_prop')
156
+ msg
157
+ end
158
+ expect(queue.first.get('message')).to eql (message)
159
+ expect(queue.first.get('jms_destination')).to be_nil
160
+ expect(queue.first.get('jms_timestamp')).to_not be_nil
161
+ expect(queue.first.get('this')).to eq('this_prop')
162
+ expect(queue.first.get('that')).to eq('that_prop')
163
+ expect(queue.first.get('the_other')).to eq('the_other_prop')
164
+ end
165
+ end
166
+
167
+ context 'when neither header nor property is skipped ' do
168
+ it 'should process properties, headers and the message' do
169
+ send_message do |session|
170
+ msg = session.message(message)
171
+ msg.set_string_property('this', 'this_prop')
172
+ msg.set_string_property('that', 'that_prop')
173
+ msg.set_string_property('the_other', 'the_other_prop')
174
+ msg
175
+ end
176
+ expect(queue.first.get('message')).to eql (message)
177
+ expect(queue.first.get('jms_timestamp')).to_not be_nil
178
+ expect(queue.first.get('jms_destination')).to_not be_nil
179
+ expect(queue.first.get('this')).to eq('this_prop')
180
+ expect(queue.first.get('that')).to eq('that_prop')
181
+ expect(queue.first.get('the_other')).to eq('the_other_prop')
182
+ end
183
+ end
184
+ end
185
+
186
+ context 'when the message is map message' do
187
+ let(:message) { {:one => 1} }
188
+ it 'should read the message' do
189
+ send_message
190
+ expect(queue.size).to eql 1
191
+ expect(queue.first.get('one')).to eql (1)
192
+ expect(queue.first.get("jms_destination")).to eql(destination)
193
+ end
194
+ end
195
+
196
+ context 'when the message is a bytes message' do
197
+ let(:message) { 'hello world'.to_java_bytes }
198
+
199
+ it 'should read the message' do
200
+ send_message do |session|
201
+ jms_message = session.createBytesMessage
202
+ jms_message.write_bytes(message)
203
+ jms_message
204
+ end
205
+ expect(queue.size).to eql 1
206
+ expect(queue.first.get('message')).to eql ('hello world')
207
+ expect(queue.first.get("jms_destination")).to eql(destination)
208
+ end
209
+ end
210
+ end
211
+ end
212
+
213
+ describe "input/jms", :integration => true do
214
+ let (:message) { "hello World" }
215
+ let (:queue_name) { SecureRandom.hex(8)}
216
+
217
+ before :each do
218
+ allow(input).to receive(:jms_config_from_yaml) do |yaml_file, section|
219
+ settings = YAML.load_file(yaml_file)[section]
220
+ settings[:require_jars] = [fixture_path("activemq-all.jar")]
221
+ settings
222
+ end
223
+ end
224
+
225
+ let (:yaml_section) { 'activemq' }
226
+ let (:jms_config) {{'yaml_file' => fixture_path("jms.yml"),
227
+ 'yaml_section' => yaml_section,
228
+ 'destination' => queue_name,
229
+ 'pub_sub' => pub_sub,
230
+ 'interval' => 2}}
231
+ let(:input) { LogStash::Plugin.lookup("input", "jms").new(jms_config) }
232
+
233
+ after :each do
234
+ input.close unless input.nil?
235
+ end
236
+
237
+ context 'with plaintext', :plaintext => true do
238
+ context 'with pub_sub true' do
239
+ let (:pub_sub) { true }
240
+ it_behaves_like 'a JMS input'
241
+ end
242
+
243
+ context 'with pub_sub true and durable subscriber' do
244
+ let (:jms_config) { super.merge({'durable_subscriber' => true,
245
+ 'durable_subscriber_client_id' => SecureRandom.hex(8),
246
+ 'durable_subscriber_name' => SecureRandom.hex(8) } ) }
247
+
248
+ let (:pub_sub) { true }
249
+
250
+ it_behaves_like 'a JMS input'
251
+ end
252
+
253
+ context 'with pub_sub false' do
254
+ let (:pub_sub) { false }
255
+ it_behaves_like 'a JMS input'
256
+ end
257
+ end
258
+
259
+ context 'with tls', :tls => true do
260
+ let (:yaml_section) { 'activemq_tls' }
261
+ let (:jms_config) { super.merge({"keystore" => fixture_path("keystore.jks"), "keystore_password" => "changeit",
262
+ "truststore" => fixture_path("keystore.jks"), "truststore_password" => "changeit"})}
263
+
264
+ context 'with pub_sub true' do
265
+ let (:pub_sub) { true }
266
+ it_behaves_like 'a JMS input'
267
+ end
268
+
269
+ context 'with pub_sub true and durable subscriber' do
270
+ let (:jms_config) { super.merge({'durable_subscriber' => true,
271
+ 'durable_subscriber_client_id' => SecureRandom.hex(8),
272
+ 'durable_subscriber_name' => SecureRandom.hex(8) } ) }
273
+
274
+ let (:pub_sub) { true }
275
+
276
+ it_behaves_like 'a JMS input'
277
+ end
278
+
279
+ context 'with pub_sub false' do
280
+ let (:pub_sub) { false }
281
+ it_behaves_like 'a JMS input'
282
+ end
283
+ end
284
+ end