This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 ClientCode( | |
@Named(MY_QUEUE_NAME) | |
private val commandScheduler: CommandScheduler | |
) { | |
fun doSomething() { | |
// ... some code ... | |
val transactionId: TransactionId = ... | |
val invoiceId: InvoiceId = ... | |
commandScheduler.schedule(PushTransactionForInvoiceSpec(transactionId, invoiceId)) |
This file contains hidden or 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
const val MY_QUEUE_NAME: String = "myServiceQueue" | |
@Configuration | |
class MyServiceQueueConfiguration { | |
@Bean(MY_QUEUE_NAME) | |
fun myServiceQueue(commandExecutionQueueFactory: CommandExecutionQueueFactory) = | |
commandExecutionQueueFactory.createQueue( | |
MY_QUEUE_NAME, |