Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,15 @@ func (ch *Channel) ExchangeUnbind(destination, key, source string, noWait bool,
)
}

// GetNextPublishSeqNo returns the sequence number of the next message to be
// published, when in confirm mode.
func (ch *Channel) GetNextPublishSeqNo() uint64 {
ch.confirms.Lock()
defer ch.confirms.Unlock()

return ch.confirms.published + 1
}

/*
Publish sends a Publishing from the client to an exchange on the server.

Expand Down
10 changes: 10 additions & 0 deletions confirms.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,13 @@ func (c *confirms) Close() error {
c.listeners = nil
return nil
}

// Lock acquire the lock on confirms.
func (c *confirms) Lock() {
c.m.Lock()
}

// Unlock release the locks on confirms.
func (c *confirms) Unlock() {
c.m.Unlock()
}
32 changes: 32 additions & 0 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,38 @@ func TestIntegrationCancel(t *testing.T) {
}
}

func TestIntegrationGetNextPublishSeqNo(t *testing.T) {
if c := integrationConnection(t, "GetNextPublishSeqNo"); c != nil {
defer c.Close()

ch, err := c.Channel()
if err != nil {
t.Fatalf("channel: %v", err)
}

if err = ch.Confirm(false); err != nil {
t.Fatalf("could not confirm")
}

ex := "test-get-next-pub"
if err = ch.ExchangeDeclare(ex, "direct", false, false, false, false, nil); err != nil {
t.Fatalf("cannot declare %v: got: %v", ex, err)
}

n := ch.GetNextPublishSeqNo()
if n != 1 {
t.Errorf("wrong next publish seqence number before any publish, expected: %d, got: %d", 1, n)
}

ch.Publish("test-get-next-pub-seq", "", false, false, Publishing{})

n = ch.GetNextPublishSeqNo()
if n != 2 {
t.Errorf("wrong next publish seqence number after 1 publishing, expected: %d, got: %d", 2, n)
}
}
}

func TestIntegrationConfirm(t *testing.T) {
if c, ch := integrationQueue(t, "confirm"); c != nil {
defer c.Close()
Expand Down