HttpEventstore is a HTTP connector to the Greg's Event Store.
Add this line to your application's Gemfile:
gem 'http_eventstore'
To communicate with ES you have to create instance of HttpEventstore::Connection
class. After configuring a client, you can do the following things.
client = HttpEventstore::Connection.new do |config|
# default value is 'http'
config.scheme = 'https'
# default value is 'localhost'
config.endpoint = 'your_endpoint'
# default value is 2113
config.port = 'your_port'
# default value is 20 entries per page
config.page_size = 'your_page_size'
end
Creating a single event:
stream_name = "order_1"
event_data = { event_type: "OrderCreated",
data: { data: "sample" },
event_id: "b2d506fd-409d-4ec7-b02f-c6d2295c7edd" }
client.append_to_stream(stream_name, event_data)
OR
EventData = Struct.new(:data, :event_type)
stream_name = "order_1"
event_data = EventData.new({ data: "sample" }, "OrderCreated")
client.append_to_stream(stream_name, event_data)
Creating a single event with optimistic locking:
stream_name = "order_1"
event_data = { event_type: "OrderCreated", data: { data: "sample" }}
expected_version = 1
client.append_to_stream(stream_name, event_data, expected_version)
The soft delete of single stream:
stream_name = "order_1"
client.delete_stream("stream_name")
The hard delete of single stream:
stream_name = "order_1"
hard_delete = true
client.delete_stream("stream_name", hard_delete)
The soft delete cause that you will be allowed to recreate the stream by creating new event. If you recreate soft deleted stream all events are lost. After an hard delete any try to load the stream or create event will result in a 410 response.
stream_name = "order_1"
start = 21
count = 40
client.read_events_forward(stream_name, start, count)
If you call following method to get the newest entries and no data is available the server wait some specified period of time.
stream_name = "order_1"
start = 21
count = 40
pool_time = 15
client.read_events_forward(stream_name, start, count, poll_time)
stream_name = "order_1"
start = 21
count = 40
client.read_events_backward(stream_name, start, count)
This method allows us to load all stream's events ascending.
stream_name = "order_1"
client.read_all_events_forward(stream_name)
This method allows us to load all stream's events descending.
stream_name = "order_1"
client.read_all_events_backward(stream_name)
To take advantage of all the functionality offered by our gem the minimum recommended version of Event Store is 2.1
- Fork it ( https://github.com/[my-github-username]/http_eventstore/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
This repository is funded and maintained by Arkency. Check out our other open-source projects.
You can also hire us or read our blog.