
io.codearte.accurest.samples.messaging.BookService.groovy Maven / Gradle / Ivy
The newest version!
package io.codearte.accurest.samples.messaging
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.cloud.stream.messaging.Source
import org.springframework.messaging.MessageHeaders
import org.springframework.messaging.support.MessageBuilder
import org.springframework.stereotype.Service
@Service
@CompileStatic
@Slf4j
class BookService {
private final Source source
@Autowired
BookService(Source source) {
this.source = source
}
/**
Scenario for "should generate tests triggered by a method":
client side: must have a possibility to "trigger" sending of a message to the given messageFrom
server side: will run the method and await upon receiving message on the output messageFrom
Method triggers sending a message to a source
*/
void returnBook(BookReturned bookReturned) {
log.info("Returning book [$bookReturned]")
source.output().send(MessageBuilder.createMessage(bookReturned, new MessageHeaders([
'BOOK-NAME': bookReturned.bookName as Object
])))
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy