logstash-output-azure_service_bus 0.2.0 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 016441e1bf597f2bdea94a9123cf4a5fb10541ee6181455bb070a623cd0d1b74
4
- data.tar.gz: 872320c9b33b392745ddd08781bbd3f6bb14516150808d9f79079ead73bd5fea
3
+ metadata.gz: d25bb98310be24692a94d2fcd87e0e5845957f42c16b923b2e9fcf381275bb1b
4
+ data.tar.gz: 514c75f9918c1e17d659d6781ed2a50b2caf28ed9a8f96a0c326d42894794116
5
5
  SHA512:
6
- metadata.gz: a69069641020d293436f0a6b9bb633734b030fc16731a006ab54deabc5e42958fbcae23c13aa370c200b51fbb8af7fe7c47f98256a9bb051fbf07a7438cd724a
7
- data.tar.gz: 9ced162d4a22745c9507c2e38800f493a04f9cb938d63ba3fcde836d5d997f9774f3eeaa28caf7c38f4fb11c22a8f15a77ae8be73d54feecf5928bd778afa43c
6
+ metadata.gz: 3d547ae59c36e62cf3da4b1919b5a5a6932fccd5132775b6762d02954533b128592b328be7376b78ba64b2aef0dd5039ab82b296f5a2986c0b3afec9494eb00b
7
+ data.tar.gz: 436eb44572d7ed0d5b4127a142c810f5c5307f33f47a0022c448b578d64e4f0a435e5954f2f0ee3363e9a0777a7ab587dac9e0d975e04cfe3a7f7f14fb436613
data/README.md CHANGED
@@ -7,7 +7,7 @@ This plugin is hosted on RubyGems.org: [https://rubygems.org/gems/logstash-outpu
7
7
  ## Install
8
8
  To install, use the plugin tool that is part of your Logstash installation:
9
9
  ```
10
- $LOGSTASH_INSTALL/bin/logstash-plugin install logstash-output-azure_service_bus
10
+ $LOGSTASH_PATH/bin/logstash-plugin install logstash-output-azure_service_bus
11
11
  ```
12
12
 
13
13
  ## Pipeline Configuration
@@ -22,6 +22,26 @@ output {
22
22
  }
23
23
  }
24
24
  ```
25
+ There is one optional setting (`messageid_field`) which sets the Service Bus `MessageId` value to an existing, unique field. If this setting is not used, Service Bus will generate an id when the message is created. The value of the provided field _must_ be unique or Service Bus will reject the message. A sample config might look like:
26
+ ```
27
+ input { ... }
28
+ filter {
29
+ uuid {
30
+ target => "[@metadata][uuid]"
31
+ }
32
+ }
33
+ output {
34
+ azure_service_bus {
35
+ service_bus_namespace => "service-bus-name"
36
+ service_bus_entity => "queue-or-topic-name"
37
+ messageid_field => "[@metadata][uuid]"
38
+ }
39
+ elasticsearch {
40
+ ...
41
+ document_id => "%{[@metadata][uuid]}"
42
+ }
43
+ }
44
+ ```
25
45
 
26
46
  ## Service Bus Configuration
27
47
  This plugin will retry sending messages if the Service Bus connection times out or returns a bad response. To avoid idempotence issues, you should enable duplicate detection on the destination queue or topic.
@@ -10,18 +10,18 @@ class LogStash::Outputs::AzureServiceBus < LogStash::Outputs::Base
10
10
 
11
11
  config :service_bus_namespace, :validate => :string, :required => true
12
12
  config :service_bus_entity, :validate => :string, :required => true
13
- config :uuid_field, :validate => :string
13
+ config :messageid_field, :validate => :string
14
14
 
15
15
  def register
16
16
  retry_options = {
17
- max: 3,
17
+ max: 5,
18
18
  interval: 1,
19
19
  interval_randomness: 0.5,
20
20
  backoff_factor: 2,
21
21
  retry_statuses: [429, 500],
22
22
  exceptions: [Faraday::ConnectionFailed, Faraday::TimeoutError, Faraday::RetriableResponse],
23
23
  methods: %i[get post],
24
- retry_block: ->(env, _options, retries, exception) { @logger.warn("Error (#{exception}) for #{env.method.upcase} #{env.url} - #{retries + 1} retry(s) left") }
24
+ retry_block: ->(env, _options, retries, exception) { @logger.warn("Problem (#{exception}) for #{env.method.upcase} #{env.url} - #{retries + 1} retry(s) left") }
25
25
  }
26
26
  @token_conn = Faraday.new(
27
27
  url: 'http://169.254.169.254/metadata/identity/oauth2/token',
@@ -49,10 +49,10 @@ class LogStash::Outputs::AzureServiceBus < LogStash::Outputs::Base
49
49
  def send_events(events)
50
50
  messages = []
51
51
  events.each do |event|
52
- if @uuid_field.nil?
52
+ if @messageid_field.nil?
53
53
  messages.append({ 'Body' => JSON.generate(event.to_hash), 'BrokerProperties' => { 'ContentType' => 'application/json' } })
54
54
  else
55
- messages.append({ 'Body' => JSON.generate(event.to_hash), 'BrokerProperties' => { 'ContentType' => 'application/json', 'MessageId' => event.get(@uuid_field) } })
55
+ messages.append({ 'Body' => JSON.generate(event.to_hash), 'BrokerProperties' => { 'ContentType' => 'application/json', 'MessageId' => event.get(@messageid_field) } })
56
56
  end
57
57
  end
58
58
  post_messages(messages)
@@ -60,13 +60,18 @@ class LogStash::Outputs::AzureServiceBus < LogStash::Outputs::Base
60
60
 
61
61
  def post_messages(messages)
62
62
  refresh_access_token if access_token_needs_refresh?
63
- response = @service_bus_conn.post('messages') do |req|
64
- req.body = JSON.generate(messages)
65
- req.headers = { 'Authorization' => "Bearer #{@access_token}", 'Content-Type' => 'application/vnd.microsoft.servicebus.json' }
63
+ begin
64
+ response = @service_bus_conn.post('messages') do |req|
65
+ req.body = JSON.generate(messages)
66
+ req.headers = { 'Authorization' => "Bearer #{@access_token}", 'Content-Type' => 'application/vnd.microsoft.servicebus.json' }
67
+ end
68
+ rescue StandardError => e
69
+ @logger.error("Error (#{e}) while sending message to Service Bus")
70
+ end
71
+ if !response.nil?
72
+ @logger.error("Error while sending message to Service Bus: HTTP #{response.status}") if response.status != 201
73
+ @logger.debug("Sent #{messages.length} message(s) to Service Bus") if response.status == 200
66
74
  end
67
- raise "Error while sending message to Service Bus: HTTP #{response.status}" if response.status != 201
68
-
69
- @logger.debug("Sent #{messages.length} message(s) to Service Bus")
70
75
  end
71
76
 
72
77
  def access_token_needs_refresh?
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-output-azure_service_bus'
3
- s.version = '0.2.0'
3
+ s.version = '0.2.3'
4
4
  s.licenses = ['Apache-2.0']
5
5
  s.summary = 'Send Logstash messages to Azure Service Bus.'
6
6
  s.homepage = 'https://github.com/gharryg/logstash-output-azure_service_bus'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-azure_service_bus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harrison Golden
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-06 00:00:00.000000000 Z
11
+ date: 2022-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement