mirror of https://github.com/reiseburo/hermann
fix bug, constantize TIMEOUT_MS, add README.md info
This commit is contained in:
parent
e38b626b71
commit
5942e1810b
16
README.md
16
README.md
|
@ -49,9 +49,9 @@ promise.state # the state of the promise
|
|||
require 'hermann/producer'
|
||||
|
||||
p = Hermann::Producer.new('topic', ['localhost:6667']) # arguments topic, list of brokers
|
||||
f = p.push('hello world from mri')
|
||||
f.state
|
||||
p.tick_reactor
|
||||
f = p.push('hello world from mri')
|
||||
f.state
|
||||
p.tick_reactor
|
||||
f.state
|
||||
```
|
||||
|
||||
|
@ -94,8 +94,18 @@ the_consumer.consume(new_topic) do |msg| # can change topic with optional argu
|
|||
end
|
||||
```
|
||||
|
||||
### Metadata request (MRI-only)
|
||||
|
||||
Topic and cluster metadata may be retrieved in the MRI version by querying the Kafka brokers.
|
||||
|
||||
```ruby
|
||||
require 'hermann'
|
||||
require 'hermann/discovery/metadata'
|
||||
|
||||
c = Hermann::Discovery::Metadata.new( "localhost:9092" )
|
||||
puts c.get_topics.inspect
|
||||
puts c.get_topics("only_this_topic").inspect
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -778,7 +778,7 @@ static VALUE producer_metadata_make_hash(struct rd_kafka_metadata *data)
|
|||
|
||||
for ( j = 0 ; j < data->topics[i].partition_cnt ; j++ ) {
|
||||
VALUE partition_hash = rb_hash_new();
|
||||
rd_kafka_metadata_partition_t *partition = &(data->topics[i].partitions[i]);
|
||||
rd_kafka_metadata_partition_t *partition = &(data->topics[i].partitions[j]);
|
||||
|
||||
/* id => 1, leader_id => 0 */
|
||||
rb_hash_aset(partition_hash, ID2SYM(rb_intern("id")), INT2FIX(partition->id));
|
||||
|
|
|
@ -3,13 +3,14 @@ require 'hermann_lib'
|
|||
module Hermann
|
||||
module Discovery
|
||||
class Metadata
|
||||
TIMEOUT_MS = 200
|
||||
def initialize(brokers)
|
||||
raise "this is an MRI api only!" if Hermann.jruby?
|
||||
@internal = Hermann::Lib::Producer.new(brokers)
|
||||
end
|
||||
|
||||
def get_topics
|
||||
@internal.metadata(nil, 200)
|
||||
def get_topics(filter_topics = nil)
|
||||
@internal.metadata(filter_topics, TIMEOUT_MS)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,5 +3,5 @@ require 'hermann'
|
|||
require 'hermann/discovery/metadata'
|
||||
|
||||
c = Hermann::Discovery::Metadata.new( "localhost:9092" )
|
||||
puts c.get_topics.inspect
|
||||
puts c.get_topics("maxwell").inspect
|
||||
|
||||
|
|
Loading…
Reference in New Issue