|
|
@@ -1,75 +0,0 @@
|
|
1
|
|
-package se.citerus.dddsample.application.messaging;
|
|
2
|
|
-
|
|
3
|
|
-import org.springframework.jms.core.JmsOperations;
|
|
4
|
|
-import org.springframework.jms.core.MessageCreator;
|
|
5
|
|
-import se.citerus.dddsample.domain.model.cargo.Cargo;
|
|
6
|
|
-import se.citerus.dddsample.domain.model.handling.CannotCreateHandlingEventException;
|
|
7
|
|
-import se.citerus.dddsample.domain.model.handling.HandlingEvent;
|
|
8
|
|
-import se.citerus.dddsample.domain.service.DomainEventNotifier;
|
|
9
|
|
-
|
|
10
|
|
-import javax.jms.Destination;
|
|
11
|
|
-import javax.jms.JMSException;
|
|
12
|
|
-import javax.jms.Message;
|
|
13
|
|
-import javax.jms.Session;
|
|
14
|
|
-
|
|
15
|
|
-/**
|
|
16
|
|
- * JMS based implementation.
|
|
17
|
|
- */
|
|
18
|
|
-public final class JmsDomainEventNotifierImpl implements DomainEventNotifier {
|
|
19
|
|
-
|
|
20
|
|
- private JmsOperations jmsOperations;
|
|
21
|
|
- private Destination cargoHandledTopic;
|
|
22
|
|
- private Destination misdirectedCargoTopic;
|
|
23
|
|
- private Destination deliveredCargoTopic;
|
|
24
|
|
-
|
|
25
|
|
- @Override
|
|
26
|
|
- public void cargoWasHandled(final HandlingEvent event) {
|
|
27
|
|
- final Cargo cargo = event.cargo();
|
|
28
|
|
- jmsOperations.send(cargoHandledTopic, new MessageCreator() {
|
|
29
|
|
- public Message createMessage(final Session session) throws JMSException {
|
|
30
|
|
- return session.createTextMessage(cargo.trackingId().idString());
|
|
31
|
|
- }
|
|
32
|
|
- });
|
|
33
|
|
- }
|
|
34
|
|
-
|
|
35
|
|
- @Override
|
|
36
|
|
- public void cargoWasMisdirected(final Cargo cargo) {
|
|
37
|
|
- jmsOperations.send(misdirectedCargoTopic, new MessageCreator() {
|
|
38
|
|
- public Message createMessage(Session session) throws JMSException {
|
|
39
|
|
- return session.createTextMessage(cargo.trackingId().idString());
|
|
40
|
|
- }
|
|
41
|
|
- });
|
|
42
|
|
- }
|
|
43
|
|
-
|
|
44
|
|
- @Override
|
|
45
|
|
- public void cargoHasArrived(final Cargo cargo) {
|
|
46
|
|
- jmsOperations.send(deliveredCargoTopic, new MessageCreator() {
|
|
47
|
|
- public Message createMessage(Session session) throws JMSException {
|
|
48
|
|
- return session.createTextMessage(cargo.trackingId().idString());
|
|
49
|
|
- }
|
|
50
|
|
- });
|
|
51
|
|
- }
|
|
52
|
|
-
|
|
53
|
|
- @Override
|
|
54
|
|
- public void rejectHandlingEventRegistrationAttempt(CannotCreateHandlingEventException e) {
|
|
55
|
|
- // TODO send to dedicated queue
|
|
56
|
|
- System.err.println("Rejected handling event registration attempt: " + e);
|
|
57
|
|
- }
|
|
58
|
|
-
|
|
59
|
|
- public void setJmsOperations(final JmsOperations jmsOperations) {
|
|
60
|
|
- this.jmsOperations = jmsOperations;
|
|
61
|
|
- }
|
|
62
|
|
-
|
|
63
|
|
- public void setCargoHandledTopic(final Destination cargoHandledTopic) {
|
|
64
|
|
- this.cargoHandledTopic = cargoHandledTopic;
|
|
65
|
|
- }
|
|
66
|
|
-
|
|
67
|
|
- public void setMisdirectedCargoTopic(Destination misdirectedCargoTopic) {
|
|
68
|
|
- this.misdirectedCargoTopic = misdirectedCargoTopic;
|
|
69
|
|
- }
|
|
70
|
|
-
|
|
71
|
|
- public void setDeliveredCargoTopic(Destination deliveredCargoTopic) {
|
|
72
|
|
- this.deliveredCargoTopic = deliveredCargoTopic;
|
|
73
|
|
- }
|
|
74
|
|
-
|
|
75
|
|
-}
|