-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More flexible CQRS config and PoisonQueueWithFilter middleware (#67)
- Loading branch information
1 parent
fe94de8
commit 6367896
Showing
18 changed files
with
692 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# UPGRADE FROM 0.3.x to 0.4 | ||
|
||
# `watermill/components/cqrs` | ||
|
||
### `CommandHandler.HandlerName` and `EventHandler.HandlerName` was added to the interface. | ||
|
||
If you are using metrics component, you may want to keep backward capability with handler names. In other case you can implement your own method of generating handler name. | ||
|
||
Keeping backward capability for **event handlers**: | ||
|
||
``` | ||
func (h CommandHandler) HandlerName() string { | ||
return fmt.Sprintf("command_processor-%s", h) | ||
} | ||
``` | ||
|
||
Keeping backward capability for **command handlers**: | ||
|
||
``` | ||
func (h EventHandler) HandlerName() string { | ||
return fmt.Sprintf("event_processor-%s", ObjectName(h)) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,45 @@ | ||
package cqrs | ||
package cqrs_test | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/ThreeDotsLabs/watermill/message" | ||
"github.com/ThreeDotsLabs/watermill/components/cqrs" | ||
) | ||
|
||
type publisherStub struct { | ||
messages map[string]message.Messages | ||
|
||
mu sync.Mutex | ||
} | ||
|
||
func newPublisherStub() *publisherStub { | ||
return &publisherStub{ | ||
messages: make(map[string]message.Messages), | ||
} | ||
} | ||
|
||
func (*publisherStub) Close() error { | ||
return nil | ||
} | ||
|
||
func (p *publisherStub) Publish(topic string, messages ...*message.Message) error { | ||
p.mu.Lock() | ||
defer p.mu.Unlock() | ||
|
||
p.messages[topic] = append(p.messages[topic], messages...) | ||
|
||
return nil | ||
} | ||
|
||
func TestCommandBus_Send_ContextPropagation(t *testing.T) { | ||
publisher := newPublisherStub() | ||
|
||
commandBus := NewCommandBus(publisher, "whatever", JSONMarshaler{}) | ||
commandBus, err := cqrs.NewCommandBus( | ||
publisher, | ||
func(commandName string) string { | ||
return "whatever" | ||
}, | ||
cqrs.JSONMarshaler{}, | ||
) | ||
require.NoError(t, err) | ||
|
||
ctx := context.WithValue(context.Background(), "key", "value") | ||
|
||
err := commandBus.Send(ctx, "message") | ||
err = commandBus.Send(ctx, "message") | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, ctx, publisher.messages["whatever"][0].Context()) | ||
} | ||
|
||
func TestCommandBus_Send_topic_name(t *testing.T) { | ||
cb, err := cqrs.NewCommandBus( | ||
assertPublishTopicPublisher{ExpectedTopic: "cqrs_test.TestCommand", T: t}, | ||
func(commandName string) string { | ||
return commandName | ||
}, | ||
cqrs.JSONMarshaler{}, | ||
) | ||
require.NoError(t, err) | ||
|
||
err = cb.Send(context.Background(), TestCommand{}) | ||
require.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.