Skip to content

Commit

Permalink
Include durable and update the client and server
Browse files Browse the repository at this point in the history
  • Loading branch information
alinz committed Apr 29, 2024
1 parent d6f53e9 commit bb56f70
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
15 changes: 9 additions & 6 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (c *Client) Put(ctx context.Context, evt *bus.Event) error {
}
}()

url := c.addr + "/"
url := c.addr + "/put"

req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, pr)
if err != nil {
Expand Down Expand Up @@ -132,8 +132,11 @@ func (c *Client) Get(ctx context.Context, consumerOpts ...bus.ConsumerOpt) iter.
if consumer.BatchSize > 0 {
qs.Set("batch_size", fmt.Sprintf("%d", consumer.BatchSize))
}
if consumer.Durable {
qs.Set("durable", "true")
}

url := c.addr + "/?" + qs.Encode()
url := c.addr + "/get?" + qs.Encode()

req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
Expand Down Expand Up @@ -224,13 +227,13 @@ func (c *Client) Ack(ctx context.Context, consumerId, eventId string) error {
var url strings.Builder

url.WriteString(c.addr)
url.WriteString("/?")
url.WriteString("/ack?")
url.WriteString("event_id=")
url.WriteString(eventId)
url.WriteString("&consumer_id=")
url.WriteString(consumerId)

req, err := http.NewRequestWithContext(ctx, http.MethodHead, url.String(), nil)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url.String(), nil)
if err != nil {
return err
}
Expand All @@ -257,10 +260,10 @@ func (c *Client) Close(ctx context.Context, consumerId string) error {
var url strings.Builder

url.WriteString(c.addr)
url.WriteString("/?consumer_id=")
url.WriteString("/delete?consumer_id=")
url.WriteString(consumerId)

req, err := http.NewRequestWithContext(ctx, http.MethodDelete, url.String(), nil)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url.String(), nil)
if err != nil {
return err
}
Expand Down
9 changes: 5 additions & 4 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ func (h *Handler) getAction(ctx context.Context, consumer *bus.Consumer) (chan [
consumer.Pattern = queue.Pattern
consumer.AckStrategy = queue.AckStrategy
consumer.AckedCount = ackedCount
consumer.Durable = false
}

// load/create consumer
Expand Down Expand Up @@ -578,10 +579,10 @@ func New(ctx context.Context, opts ...Opt) (*Handler, error) {

h.dbw = sqlite.NewWorker(db, int64(conf.workerBufferSize), int64(conf.dbPoolSize))

h.mux.HandleFunc("POST /", h.publishHandler) // POST /
h.mux.HandleFunc("GET /", h.consumerHandler) // GET /?subject=foo&durable&queue=bar&pos=oldest|newest|<event_id>&id=123&auto_ack
h.mux.HandleFunc("HEAD /", h.ackedHandler) // HEAD /?consumer_id=123&event_id=456
h.mux.HandleFunc("DELETE /", h.deleteConsumerHandler) // DELETE /?consumer_id=123
h.mux.HandleFunc("POST /put", h.publishHandler) // POST /put
h.mux.HandleFunc("GET /get", h.consumerHandler) // GET /get?subject=foo&durable&queue=bar&pos=oldest|newest|<event_id>&id=123&auto_ack
h.mux.HandleFunc("GET /ack", h.ackedHandler) // GET /ack?consumer_id=123&event_id=456
h.mux.HandleFunc("GET /delete", h.deleteConsumerHandler) // GET /delete?consumer_id=123

go h.removeExpiredEventsLoop(ctx, conf.cleanExpiredEventsFreq)

Expand Down

0 comments on commit bb56f70

Please sign in to comment.