Module: Qian::Event
- Included in:
- Qian::Events::Engagement
- Defined in:
- lib/qian/event.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#attrs_with_string_key ⇒ String
将自己 encode 为 avro binary data.
-
#avro_encoded_data ⇒ String
将自己 encode 为 avro binary data.
-
#emit! ⇒ void
将自己事件发送出去.
Class Method Details
.included(base) ⇒ 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 30 31 32 33 34 35 36 37 38 |
# File 'lib/qian/event.rb', line 4 def self.included(base) base.class_eval do include Virtus.value_object(:strict => true) # # 设置当前 Event 的 Kafka Topic # # @param [<type>] topic_name <description> # # @return [<type>] <description> # def self.kafka_topic(topic_name) @kafka_topic_name = topic_name.to_s end # # 返回当前 Event 的 Kafka Topic # # @return [String] # def self.kafka_topic_name @kafka_topic_name end # # 当前 Event 类型对应的 Avro Schema 全名 # # # @return [String] # def self.avro_schema_name "com.jianshu.event.#{Qian::Util.convert_class_name_to_package_name(self.to_s)}" end end end |
Instance Method Details
#attrs_with_string_key ⇒ String
将自己 encode 为 avro binary data
-
Avro::Turf 只接受
57 58 59 |
# File 'lib/qian/event.rb', line 57 def attrs_with_string_key self.attributes.deep_stringify_keys end |
#avro_encoded_data ⇒ String
将自己 encode 为 avro binary data
67 68 69 |
# File 'lib/qian/event.rb', line 67 def avro_encoded_data Qian.avro.encode(self.attrs_with_string_key, :schema_name => self.class.avro_schema_name) end |
#emit! ⇒ void
This method returns an undefined value.
将自己事件发送出去
46 47 48 |
# File 'lib/qian/event.rb', line 46 def emit! Qian.kafka_producer.produce(avro_encoded_data, :topic => self.class.kafka_topic_name) end |