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
@Component | |
class PushTransactionForInvoice( | |
private val transactionPushService: TransactionPushService | |
) : Command(PushTransactionForInvoiceSpec::class) { | |
override fun execute(arguments: Map<String, Any?>): CommandExecutionResult { | |
val invoiceId = InvoiceId(arguments["invoiceId"] as String) | |
val transactionId = TransactionId(arguments["transactionId"] as String) | |
transactionPushService.pushTransactionForInvoice(transactionId, invoiceId) |
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
import com.thoughtworks.qdox.JavaProjectBuilder; | |
import com.thoughtworks.qdox.model.*; | |
import org.junit.Test; | |
import java.io.*; | |
import java.text.MessageFormat; | |
import java.util.*; | |
import static java.util.Arrays.asList; | |
import static java.util.Arrays.stream; |
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
import org.junit.runner.RunWith; | |
import org.springframework.test.context.ContextConfiguration; | |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | |
@RunWith(SpringJUnit4ClassRunner.class) | |
@ContextConfiguration(classes = { | |
// only populate the context with the classes that interest us for this test | |
SomePublisher.class, | |
JvmSynchronizedEventsService.class, | |
SomeConsumer.class |
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
@Value | |
public class EmailUpdated implements Event { | |
public static final String EXCHANGE_NAME = "email.updated.exchange"; | |
String accountId; | |
String oldEmail; | |
String newEmail; | |
} |
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
import lombok.Value; | |
// This code only works if compiling the code using javac's -parameters option (Java 8 only). | |
// With this option, Jackons can use the all-args constructor of our type. | |
// See https://gist.github.com/ndemengel/72f362bc31afe5fcaa0499af8f269651 for a more general solution. | |
@Value | |
public class EmailUpdated implements Event { | |
public static final String EXCHANGE_NAME = "email.updated.exchange"; |
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
// the exchange is not mentioned anymore here | |
@RabbitEventListener(queue = "email.updated.mailchimp.queue") | |
public void emailUpdated(EmailUpdated event) { | |
updateMailChimpMember(event.getOldEmail(), event.getNewEmail()); | |
} |
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
// let's use our own annotation! | |
@RabbitEventListener(queue = "email.updated.mailchimp.queue", exchange = RabbitConfig.EMAIL_UPDATED_EXCHANGE) | |
public void emailUpdated(EmailUpdated event) { | |
updateMailChimpMember(event.getOldEmail(), event.getNewEmail()); | |
} |
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
@PostConstruct | |
public void createExchangesAndQueuesAndBindings() { | |
// only one line left for each exchange/queues association! | |
createAndBindQueuesToFanoutExchangeAndDeadLetter(EMAIL_UPDATED_EXCHANGE, MAILCHIMP_EMAIL_UPDATED_QUEUE); | |
// ... other associations... | |
} | |
private void createAndBindQueuesToFanoutExchangeAndDeadLetter(String exchangeName, String... queueNames) { | |
FanoutExchange exchangeBean = createExchangeBean(exchangeName); |
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
import lombok.Data; | |
@Data | |
public final class EmailUpdated { | |
private String accountId; | |
private String oldEmail; | |
private String newEmail; | |
public EmailUpdated(String accountId, String oldEmail, String newEmail) { | |
this.accountId = accountId; |
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
import lombok.*; | |
// The aim here is to have a type that looks like a value type, while still | |
// allowing Jackson to unmarshal our type from JSON. | |
// See https://gist.github.com/ndemengel/77a8ffbb929bc55e3d87809820c1c5a4 for a more elegant solution. | |
@AllArgsConstructor @Getter | |
@EqualsAndHashCode @ToString | |
@NoArgsConstructor(access = AccessLevel.PRIVATE) | |
public final class EmailUpdated implements Event<EmailUpdated> { |