forked from yahoo/elide-doc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aaron Klish
committed
Sep 30, 2021
1 parent
7016d87
commit d60c156
Showing
2 changed files
with
80 additions
and
10 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,50 @@ | ||
files: | ||
- ChatBot.java | ||
- ChatBotCreateHook.java | ||
|
||
ChatBot.java: |+2 | ||
```java | ||
@Include | ||
@Data | ||
@LifeCycleHookBinding( | ||
hook = ChatBotCreateHook.class, | ||
operation = LifeCycleHookBinding.Operation.CREATE, | ||
phase = LifeCycleHookBinding.TransactionPhase.POSTCOMMIT | ||
) | ||
public class ChatBot { | ||
@Id | ||
long id; | ||
String name; | ||
} | ||
``` | ||
ChatBotCreateHook.java: |+2 | ||
```java | ||
@Data | ||
public class ChatBotCreateHook implements LifeCycleHook<ChatBot> { | ||
@Inject | ||
ConnectionFactory connectionFactory; | ||
@Override | ||
public void execute( | ||
LifeCycleHookBinding.Operation operation, | ||
LifeCycleHookBinding.TransactionPhase phase, | ||
ChatBot bot, | ||
RequestScope requestScope, | ||
Optional<ChangeSpec> changes) { | ||
NotifyTopicLifeCycleHook<Chat> publisher = new NotifyTopicLifeCycleHook<>( | ||
connectionFactory, | ||
new ObjectMapper(), | ||
JMSContext::createProducer | ||
); | ||
publisher.publish(new Chat(1, "Hello!"), CHAT); | ||
publisher.publish(new Chat(2, "How is your day?"), CHAT); | ||
publisher.publish(new Chat(3, "My name is " + bot.getName()), CHAT); | ||
} | ||
} | ||
``` |
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