Class: LogStash::Outputs::AzureEventHubs

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/outputs/azure_event_hubs.rb

Overview

Output plugin to send events to an Azure Event Hub.

Instance Method Summary collapse

Instance Method Details

#closeObject



137
138
139
140
# File 'lib/logstash/outputs/azure_event_hubs.rb', line 137

def close
  @eventhub_client.closeSync();
  @executor_service.shutdown();
end

#receive(event) ⇒ Object



143
144
145
146
147
148
149
# File 'lib/logstash/outputs/azure_event_hubs.rb', line 143

def receive(event)
  begin
    @codec.encode(event)
  rescue => e
    @logger.warn("Error encoding event", :exception => e, :event => event)
  end
end

#registerObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/logstash/outputs/azure_event_hubs.rb', line 78

def register
  # Build Event Hubs client connection string

  connection_builder = ConnectionStringBuilder.new()
  connection_builder.setNamespaceName(@service_namespace)
  connection_builder.setEventHubName(@event_hub)
  connection_builder.setSasKeyName(@sas_key_name)
  connection_builder.setSasKey(@sas_key)

  # Configure for national cloud

  if (!@service_domain.nil?)
    connection_builder.setEndpoint(@service_namespace, @service_domain)
  end

  # The Executor handles all the asynchronous tasks and this is passed to the EventHubClient.

  # The gives the user control to segregate their thread pool based on the work load.

  # This pool can then be shared across multiple EventHubClient instances.

  @executor_service = Executors.newScheduledThreadPool(@client_threads)

  # Handle Transient errors when creating the Event Hubs Client

  try = 0
  retry_interval = 2
  begin
    # Each EventHubClient instance spins up a new TCP/SSL connection, which is expensive.

    # It is always a best practice to reuse these instances.

    @eventhub_client = EventHubClient.createSync(connection_builder.toString(), @executor_service)

  rescue EventHubException, ExecutionException, InterruptedException, IOException => e
    # Log error, no retry

    if e.getIsTransient() != true or e == IOException or try >= @connection_retry_count
      @logger.error(
        "Unable to establish connection to Azure Event Hubs.",
        :error_message => e.getMessage(),
        :class => e.class.name
        )
      close()
      exit(1)
    end

    # Log error with retry

    @logger.error(
      "Connection to Event Hubs failed, will attempt connection again.",
      :error_message => e.getMessage(),
      :class => e.class.name,
      :retry_in_seconds => retry_interval
    )

    # Wait for interval

    sleep(retry_interval)
    
    # Add attempt and retry

    try += 1
    retry
  end

  # Pass event to sender on encode 

  @codec.on_event(&method(:send_record))
end