mirror of https://github.com/reiseburo/hermann
exploratory work
This commit is contained in:
parent
9d173ef84d
commit
fad37247d3
|
@ -46,12 +46,16 @@ module Hermann
|
||||||
# will be set
|
# will be set
|
||||||
def push_single(msg, topic, unused)
|
def push_single(msg, topic, unused)
|
||||||
Concurrent::Promise.execute {
|
Concurrent::Promise.execute {
|
||||||
data = ProducerUtil::KeyedMessage.new(topic, msg)
|
|
||||||
begin
|
begin
|
||||||
|
data = ProducerUtil::KeyedMessage.new(topic, msg)
|
||||||
|
# begin
|
||||||
@producer.send(data)
|
@producer.send(data)
|
||||||
rescue Java::KafkaCommon::FailedToSendMessageException => jexc
|
rescue Exception => e
|
||||||
raise Hermann::Errors::ConnectivityError.new(jexc.message,
|
# rescue Java::KafkaCommon::FailedToSendMessageException => jexc
|
||||||
:java_exception => jexc)
|
# raise Hermann::Errors::ConnectivityError.new(jexc.message,
|
||||||
|
# :java_exception => jexc)
|
||||||
|
puts "............#{e.message}"
|
||||||
|
puts e.backtrace.join("\n")
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -60,7 +60,7 @@ module Hermann
|
||||||
stream = get_stream(topic)
|
stream = get_stream(topic)
|
||||||
it = stream.iterator
|
it = stream.iterator
|
||||||
while it.hasNext do
|
while it.hasNext do
|
||||||
yield it.next.message.to_s
|
yield it.next
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
puts "#{self.class.name}#consume exception: #{e.class.name}"
|
puts "#{self.class.name}#consume exception: #{e.class.name}"
|
||||||
|
|
|
@ -22,28 +22,32 @@ describe 'producer' do
|
||||||
puts "consuming off `#{topic}`"
|
puts "consuming off `#{topic}`"
|
||||||
consumer.consume(topic) do |dequeued|
|
consumer.consume(topic) do |dequeued|
|
||||||
puts "received the message: #{dequeued.inspect}"
|
puts "received the message: #{dequeued.inspect}"
|
||||||
value = dequeued
|
|
||||||
|
buffer = dequeued.message.to_a
|
||||||
|
# value = String.from_java_bytes(dequeued.message)
|
||||||
|
value = buffer.pack('C*').encode('UTF-8', {:invalid => :replace, :undef => :replace, :replace => ''})
|
||||||
|
# puts ".......................encoding: #{buffer.pack('c*')} #{buffer.pack('c*').encoding}"
|
||||||
|
|
||||||
|
# value = buffer.pack('c*').encode("ASCII-8BIT", {:invalid => :replace, :undef => :replace, :replace => ''})
|
||||||
|
puts value
|
||||||
consumer.shutdown
|
consumer.shutdown
|
||||||
end
|
end
|
||||||
# Return this out of the block
|
# Return this out of the block
|
||||||
next value
|
value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
let(:brokers) do
|
let(:brokers_array) do
|
||||||
broker_ids = Hermann::Discovery::Zookeeper.new(zookeepers).get_brokers
|
broker_ids = Hermann::Discovery::Zookeeper.new(zookeepers).get_brokers
|
||||||
puts "using ZK discovered brokers: #{broker_ids}"
|
puts "using ZK discovered brokers: #{broker_ids}"
|
||||||
broker_ids
|
broker_ids
|
||||||
end
|
end
|
||||||
let(:producer) { Hermann::Producer.new(nil, brokers) }
|
let(:producer) { Hermann::Producer.new(nil, brokers_array) }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
it 'produces and consumes messages', :type => :integration, :platform => :java do
|
it 'produces and consumes messages', :type => :integration, :platform => :java do
|
||||||
producer.push(message, :topic => topic).value!(timeout)
|
producer.push(message, :topic => topic).value!(timeout)
|
||||||
expect(consumer_promise.value!(timeout)).to eql(message)
|
expect(consumer_promise.value!(timeout)).to eql(message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
context 'with binary data', :type => :integration, :platform => :java do
|
context 'with binary data', :type => :integration, :platform => :java do
|
||||||
let(:event) do
|
let(:event) do
|
||||||
Hermann::TestEvent.new(:name => 'rspec',
|
Hermann::TestEvent.new(:name => 'rspec',
|
||||||
|
@ -56,7 +60,7 @@ describe 'producer' do
|
||||||
it 'should be a thing' do
|
it 'should be a thing' do
|
||||||
producer.push(message, :topic => topic).value!(timeout)
|
producer.push(message, :topic => topic).value!(timeout)
|
||||||
dequeued = consumer_promise.value!(timeout)
|
dequeued = consumer_promise.value!(timeout)
|
||||||
expect(dequeued).to eql(message)
|
expect(dequeued).to eql(message.encode!('UTF-8', {:invalid => :replace, :undef => :replace, :replace => ''}))
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
Hermann::TestEvent.decode(dequeued)
|
Hermann::TestEvent.decode(dequeued)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
require 'yaml'
|
require 'yaml'
|
||||||
require 'rspec'
|
require 'rspec'
|
||||||
|
require 'pry'
|
||||||
|
|
||||||
# Add ext/ to the load path so we can load `hermann_lib`
|
# Add ext/ to the load path so we can load `hermann_lib`
|
||||||
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../ext/'))
|
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../ext/'))
|
||||||
|
|
Loading…
Reference in New Issue