Class: Turbo::Train::FanoutServer
- Inherits:
-
BaseServer
- Object
- BaseServer
- Turbo::Train::FanoutServer
- Defined in:
- lib/turbo/train/fanout_server.rb
Instance Attribute Summary
Attributes inherited from BaseServer
Instance Method Summary collapse
Methods inherited from BaseServer
#initialize, #listen_url, #publish_url
Constructor Details
This class inherits a constructor from Turbo::Train::BaseServer
Instance Method Details
#publish(topics:, data:) ⇒ Object
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 |
# File 'lib/turbo/train/fanout_server.rb', line 4 def publish(topics:, data:) uri = URI(server_config.publish_url) req = Net::HTTP::Post.new(uri) req['Fastly-Key'] = server_config.fastly_key = data[:data].gsub("\n", "") payload = {items: []} Array(topics).each do |topic| payload[:items] << {channel: topic, formats: { 'http-stream': { content: "event: message\ndata: #{}\n\n" } } } end req.body = payload.to_json opts = { use_ssl: uri.scheme == 'https' } if configuration.skip_ssl_verification opts[:verify_mode] = OpenSSL::SSL::VERIFY_NONE end Net::HTTP.start(uri.host, uri.port, opts) do |http| http.request(req) end end |
#server_config ⇒ Object
31 32 33 |
# File 'lib/turbo/train/fanout_server.rb', line 31 def server_config configuration.fanout end |