Просмотр исходного кода

Altered application events and emssaging infrastructure to reflect that handling event registration is now synchronous.

peter_backlund 17 лет назад
Родитель
Сommit
941d4c2e0a

+ 8
- 8
dddsample/src/main/java/se/citerus/dddsample/application/ApplicationEvents.java Просмотреть файл

@@ -2,7 +2,6 @@ package se.citerus.dddsample.application;
2 2
 
3 3
 import se.citerus.dddsample.domain.model.cargo.Cargo;
4 4
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
5
-import se.citerus.dddsample.interfaces.handling.HandlingEventRegistrationAttempt;
6 5
 
7 6
 /**
8 7
  * This interface provides a way to let other parts
@@ -21,6 +20,14 @@ public interface ApplicationEvents {
21 20
   void cargoWasHandled(HandlingEvent event);
22 21
 
23 22
   /**
23
+   * Cargo delivery has been updated.
24
+   * @param cargo cargo
25
+   */
26
+  void cargoDeliveryWasUpdated(Cargo cargo);
27
+
28
+  // TODO remove the two below 
29
+
30
+  /**
24 31
    * A cargo has been misdirected.
25 32
    *
26 33
    * @param cargo cargo
@@ -34,11 +41,4 @@ public interface ApplicationEvents {
34 41
    */
35 42
   void cargoHasArrived(Cargo cargo);
36 43
 
37
-  /**
38
-   * A handling event regitration attempt is received.
39
-   *
40
-   * @param attempt handling event registration attempt
41
-   */
42
-  void receivedHandlingEventRegistrationAttempt(HandlingEventRegistrationAttempt attempt);
43
-
44 44
 }

+ 3
- 0
dddsample/src/main/java/se/citerus/dddsample/application/impl/CargoInspectionServiceImpl.java Просмотреть файл

@@ -51,6 +51,9 @@ public class CargoInspectionServiceImpl implements CargoInspectionService {
51 51
     }
52 52
 
53 53
     cargoRepository.store(cargo);
54
+
55
+    // TODO replace the inspections above with subscribers to this event
56
+    //applicationEvents.cargoDeliveryWasUpdated(cargo);
54 57
   }
55 58
 
56 59
 }

+ 16
- 22
dddsample/src/main/java/se/citerus/dddsample/infrastructure/messaging/jms/JmsApplicationEventsImpl.java Просмотреть файл

@@ -7,7 +7,6 @@ import org.springframework.jms.core.MessageCreator;
7 7
 import se.citerus.dddsample.application.ApplicationEvents;
8 8
 import se.citerus.dddsample.domain.model.cargo.Cargo;
9 9
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
10
-import se.citerus.dddsample.interfaces.handling.HandlingEventRegistrationAttempt;
11 10
 
12 11
 import javax.jms.Destination;
13 12
 import javax.jms.JMSException;
@@ -23,8 +22,7 @@ public final class JmsApplicationEventsImpl implements ApplicationEvents {
23 22
   private Destination cargoHandledQueue;
24 23
   private Destination misdirectedCargoQueue;
25 24
   private Destination deliveredCargoQueue;
26
-  private Destination rejectedRegistrationAttemptsQueue;
27
-  private Destination handlingEventQueue;
25
+  private Destination cargoDeliveryUpdateQueue;
28 26
 
29 27
   private static final Log logger = LogFactory.getLog(JmsApplicationEventsImpl.class);
30 28
 
@@ -34,37 +32,37 @@ public final class JmsApplicationEventsImpl implements ApplicationEvents {
34 32
     logger.info("Cargo was handled " + cargo);
35 33
     jmsOperations.send(cargoHandledQueue, new MessageCreator() {
36 34
       public Message createMessage(final Session session) throws JMSException {
37
-        return session.createTextMessage(cargo.trackingId().idString());
35
+        return session.createTextMessage(cargo.trackingId().stringValue());
38 36
       }
39 37
     });
40 38
   }
41 39
 
42 40
   @Override
43
-  public void cargoWasMisdirected(final Cargo cargo) {
44
-    logger.info("Cargo was misdirected " + cargo);
45
-    jmsOperations.send(misdirectedCargoQueue, new MessageCreator() {
41
+  public void cargoDeliveryWasUpdated(final Cargo cargo) {
42
+    logger.info("Cargo delivery was updated: " + cargo);
43
+    jmsOperations.send(cargoDeliveryUpdateQueue, new MessageCreator() {
46 44
       public Message createMessage(Session session) throws JMSException {
47
-        return session.createTextMessage(cargo.trackingId().idString());
45
+        return session.createTextMessage(cargo.trackingId().stringValue());
48 46
       }
49 47
     });
50 48
   }
51 49
 
52 50
   @Override
53
-  public void cargoHasArrived(final Cargo cargo) {
54
-    logger.info("Cargo has arrived " + cargo);
55
-    jmsOperations.send(deliveredCargoQueue, new MessageCreator() {
51
+  public void cargoWasMisdirected(final Cargo cargo) {
52
+    logger.info("Cargo was misdirected " + cargo);
53
+    jmsOperations.send(misdirectedCargoQueue, new MessageCreator() {
56 54
       public Message createMessage(Session session) throws JMSException {
57
-        return session.createTextMessage(cargo.trackingId().idString());
55
+        return session.createTextMessage(cargo.trackingId().stringValue());
58 56
       }
59 57
     });
60 58
   }
61 59
 
62 60
   @Override
63
-  public void receivedHandlingEventRegistrationAttempt(final HandlingEventRegistrationAttempt attempt) {
64
-    logger.info("Received handling event registration attempt " + attempt);
65
-    jmsOperations.send(handlingEventQueue, new MessageCreator() {
61
+  public void cargoHasArrived(final Cargo cargo) {
62
+    logger.info("Cargo has arrived " + cargo);
63
+    jmsOperations.send(deliveredCargoQueue, new MessageCreator() {
66 64
       public Message createMessage(Session session) throws JMSException {
67
-        return session.createObjectMessage(attempt);
65
+        return session.createTextMessage(cargo.trackingId().stringValue());
68 66
       }
69 67
     });
70 68
   }
@@ -85,11 +83,7 @@ public final class JmsApplicationEventsImpl implements ApplicationEvents {
85 83
     this.deliveredCargoQueue = destination;
86 84
   }
87 85
 
88
-  public void setRejectedRegistrationAttemptsQueue(Destination destination) {
89
-    this.rejectedRegistrationAttemptsQueue = destination;
90
-  }
91
-
92
-  public void setHandlingEventQueue(Destination destination) {
93
-    this.handlingEventQueue = destination;
86
+  public void setCargoDeliveryUpdateQueue(Destination cargoDeliveryUpdateQueue) {
87
+    this.cargoDeliveryUpdateQueue = cargoDeliveryUpdateQueue;
94 88
   }
95 89
 }

+ 2
- 9
dddsample/src/main/resources/context-infrastructure-messaging.xml Просмотреть файл

@@ -16,12 +16,10 @@
16 16
   <amq:queue id="cargoHandledQueue" name="CargoHandledQueue" physicalName="CargoHandledQueue"/>
17 17
   <amq:queue id="misdirectedCargoQueue" name="MisdirectedCargoQueue" physicalName="MisdirectedCargoQueue"/>
18 18
   <amq:queue id="deliveredCargoQueue" name="DeliveredCargoQueue" physicalName="DeliveredCargoQueue"/>
19
-  <amq:queue id="handlingEventRegistrationAttemptQueue" name="HandlingEventRegistrationAttemptQueue" physicalName="HandlingEventRegistrationAttemptQueue"/>
20
-  <amq:queue id="rejectedRegistrationAttemptsQueue" name="RejectedRegistrationAttemptsQueue" physicalName="RejectedRegistrationAttemptsQueue"/>
19
+  <amq:queue id="cargoDeliveryUpdateQueue" name="CargoDeliveryUpdateQueue" physicalName="CargoDeliveryUpdateQueue"/>
21 20
 
22 21
   <jms:listener-container connection-factory="jmsConnectionFactory">
23 22
     <jms:listener destination="CargoHandledQueue" ref="cargoHandledConsumer" />
24
-    <jms:listener destination="HandlingEventRegistrationAttemptQueue" ref="handlingEventRegistrationAttemptConsumer" />
25 23
     <jms:listener destination="MisdirectedCargoQueue" ref="simpleLoggingConsumer"/>
26 24
     <jms:listener destination="DeliveredCargoQueue" ref="simpleLoggingConsumer"/>
27 25
     <jms:listener destination="RejectedRegistrationAttemptsQueue" ref="simpleLoggingConsumer"/>
@@ -36,18 +34,13 @@
36 34
     <property name="cargoHandledQueue" ref="cargoHandledQueue"/>
37 35
     <property name="misdirectedCargoQueue" ref="misdirectedCargoQueue"/>
38 36
     <property name="deliveredCargoQueue" ref="deliveredCargoQueue"/>
39
-    <property name="rejectedRegistrationAttemptsQueue" ref="rejectedRegistrationAttemptsQueue"/>
40
-    <property name="handlingEventQueue" ref="handlingEventRegistrationAttemptQueue"/>
37
+    <property name="cargoDeliveryUpdateQueue" ref="cargoDeliveryUpdateQueue"/>
41 38
   </bean>
42 39
 
43 40
   <bean id="cargoHandledConsumer" class="se.citerus.dddsample.infrastructure.messaging.jms.CargoHandledConsumer">
44 41
     <property name="cargoInspectionService" ref="cargoInspectionService"/>
45 42
   </bean>
46 43
 
47
-  <bean id="handlingEventRegistrationAttemptConsumer" class="se.citerus.dddsample.infrastructure.messaging.jms.HandlingEventRegistrationAttemptConsumer">
48
-    <property name="handlingEventService" ref="handlingEventService"/>
49
-  </bean>
50
-
51 44
   <bean id="simpleLoggingConsumer" class="se.citerus.dddsample.infrastructure.messaging.jms.SimpleLoggingConsumer"/>
52 45
 
53 46
 </beans>

+ 6
- 6
dddsample/src/test/java/se/citerus/dddsample/infrastructure/messaging/stub/SynchronousApplicationEventsStub.java Просмотреть файл

@@ -6,7 +6,6 @@ import se.citerus.dddsample.application.ApplicationEvents;
6 6
 import se.citerus.dddsample.application.CargoInspectionService;
7 7
 import se.citerus.dddsample.domain.model.cargo.Cargo;
8 8
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
9
-import se.citerus.dddsample.interfaces.handling.HandlingEventRegistrationAttempt;
10 9
 
11 10
 public class SynchronousApplicationEventsStub implements ApplicationEvents {
12 11
 
@@ -24,17 +23,18 @@ public class SynchronousApplicationEventsStub implements ApplicationEvents {
24 23
   }
25 24
 
26 25
   @Override
26
+  public void cargoDeliveryWasUpdated(Cargo cargo) {
27
+    logger.debug("EVENT: cargo delivery was updated");
28
+  }
29
+
30
+  @Override
27 31
   public void cargoWasMisdirected(Cargo cargo) {
28 32
     logger.debug("EVENT: cargo was misdirected");
29 33
   }
30 34
 
31 35
   @Override
32 36
   public void cargoHasArrived(Cargo cargo) {
33
-    logger.debug("EVENT: cargo has arrived: " + cargo.trackingId().idString());
37
+    logger.debug("EVENT: cargo has arrived: " + cargo.trackingId().stringValue());
34 38
   }
35 39
 
36
-  @Override
37
-  public void receivedHandlingEventRegistrationAttempt(HandlingEventRegistrationAttempt attempt) {
38
-    logger.debug("EVENT: received handling event registration attempt");
39
-  }
40 40
 }