本文整理汇总了Java中org.springframework.amqp.rabbit.annotation.RabbitListener类的典型用法代码示例。如果您正苦于以下问题:Java RabbitListener类的具体用法?Java RabbitListener怎么用?Java RabbitListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RabbitListener类属于org.springframework.amqp.rabbit.annotation包,在下文中一共展示了RabbitListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: save
import org.springframework.amqp.rabbit.annotation.RabbitListener; //导入依赖的package包/类
@RabbitListener(bindings = @QueueBinding(
value = @Queue,
exchange = @Exchange(value = "learning-spring-boot"),
key = "comments.new"
))
public void save(Comment newComment) {
repository
.save(newComment)
.log("commentService-save")
.subscribe(comment -> {
meterRegistry
.counter("comments.consumed", "imageId", comment.getImageId())
.increment();
});
}
示例2: objectMessage
import org.springframework.amqp.rabbit.annotation.RabbitListener; //导入依赖的package包/类
@RabbitListener(queues = "seqQueue")
public void objectMessage(@Payload UserDTO msg, @Header("my-header") String my_header, Message message) {
System.out.println("message user:" + msg.getName());
String myHeader =(String) message.getMessageProperties().getHeaders().get("my-header");
logger.info("Here is my header:" + myHeader );
logger.info("my header from annotation:" +my_header);
try{
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(msg);
logger.info("here is the message recived: " + json);
}
catch (JsonProcessingException exc){
logger.info("exceptions ",exc);
}
}
示例3: getAllEvent
import org.springframework.amqp.rabbit.annotation.RabbitListener; //导入依赖的package包/类
/**
* method to get all the events
* @param id
* @return
* @throws JsonProcessingException
*/
@RabbitListener(queues = "#{getAllEventQueue.name}")
public String getAllEvent(byte[] id){
String res = "";
List<Event> events = repository.findAll();
ObjectMapper mapper = new ObjectMapper();
Log
.forContext("MemberName", "getAllEvent")
.forContext("Service", appName)
.information("RabbitMQ : getAllEvent");
try {
res = mapper.writeValueAsString(events);
} catch (JsonProcessingException e1) {
Log
.forContext("MemberName", "getAllEvent")
.forContext("Service", appName)
.error(e1,"JsonProcessingException");
}
return res;
}
示例4: handleMessage
import org.springframework.amqp.rabbit.annotation.RabbitListener; //导入依赖的package包/类
@RabbitListener(queues = "${mq.queue.osm-data-importer.name}")
public void handleMessage(ImportDataMessage message)
{
LOGGER.info(" received <{}>", message);
OsmConverterResult result = null;
if (KIND_NODES.equals(message.getKind()))
{
result = osmConverterService.importNodes(message.getPath());
}
else if (KIND_WAYS.equals(message.getKind()))
{
result = osmConverterService.importWays(message.getPath());
}
if (result != null)
{
slackNotifier.notify(SlackNotifier.CHANNEL_IMPORTS, prettyPrint(result));
}
LOGGER.info(" done with handleMessage <{}>", message);
}
示例5: getEventByPlace
import org.springframework.amqp.rabbit.annotation.RabbitListener; //导入依赖的package包/类
/**
* method to get an event by his place
* @param place
* @return
* @throws UnsupportedEncodingException
*/
@RabbitListener(queues = "#{getEventByPlaceQueue.name}")
public String getEventByPlace(byte[] place){
String res = "";
Log
.forContext("MemberName", "getEventByPlace")
.forContext("Service", appName)
.information("RabbitMQ : getEventByPlace");
try {
res = repository.getEventFromPlace(new String(place, ENCODE), new Date()).toString();
} catch (UnsupportedEncodingException e1) {
Log
.forContext("MemberName", "getEventByPlace")
.forContext("Service", appName)
.error(e1,"UnsupportedEncodingException");
}
return res;
}
示例6: getAllEventType
import org.springframework.amqp.rabbit.annotation.RabbitListener; //导入依赖的package包/类
/**
* method to get all the events type
* @param id
* @return
* @throws JsonProcessingException
*/
@RabbitListener(queues = "#{getAllEventTypeQueue.name}")
public String getAllEventType(byte[] id){
String res = "";
List<EventType> eventsType = eventTypeRepository.findAll();
ObjectMapper mapper = new ObjectMapper();
Log
.forContext("MemberName", "getAllEventType")
.forContext("Service", appName)
.information("RabbitMQ : getAllEventType");
try {
res = mapper.writeValueAsString(eventsType);
} catch (JsonProcessingException e1) {
Log
.forContext("MemberName", "getAllEventType")
.forContext("Service", appName)
.error(e1,"JsonProcessingException");
}
return res;
}
示例7: getAllPerson
import org.springframework.amqp.rabbit.annotation.RabbitListener; //导入依赖的package包/类
/**
* Method to get all Persons in DataBase, works with RabbitMq
* @param id
* @return
*/
@RabbitListener(queues = "#{getAllPersonQueue.name}")
public String getAllPerson(byte[] id){
String response = "";
List<Person> persons = repository.findAll();
ObjectMapper mapper = new ObjectMapper();
try {
response = mapper.writeValueAsString(persons);
} catch (JsonProcessingException e) {
Log
.forContext("MemberName", "getAllPerson")
.forContext("Service", appName)
.error(e," JsonProcessingException");
}
Log
.forContext("MemberName", "getAllPerson")
.forContext("Service", appName)
.information("Request : getAllPerson");
return response;
}
示例8: saveEvent
import org.springframework.amqp.rabbit.annotation.RabbitListener; //导入依赖的package包/类
/**
* method to save a suggestion in the DB
* @param data
* @return
* @throws JsonProcessingException
*/
@RabbitListener(queues = "#{saveSuggestionQueue.name}")
public String saveEvent(byte[] data){
String res = "";
Suggestion s = (Suggestion)SerializationUtils.deserialize(data);
s = repository.save(s);
ObjectMapper mapper = new ObjectMapper();
Log
.forContext("MemberName", "saveSuggestion")
.forContext("Service", appName)
.information("RabbitMQ : saveSuggestion");
try {
res = mapper.writeValueAsString(s);
} catch (JsonProcessingException e1) {
Log
.forContext("MemberName", "saveSuggestion")
.forContext("Service", appName)
.error(e1,"JsonProcessingException");
}
return res;
}
示例9: updateCustomer
import org.springframework.amqp.rabbit.annotation.RabbitListener; //导入依赖的package包/类
@RabbitListener(queues = {"customer.update"})
public void updateCustomer(String message) throws InterruptedException, IOException {
Profile profile = objectMapper.readValue(message, Profile.class);
try {
// Update the customer service for the profile
UpdateCustomerResponse response =
customerClient.updateCustomerResponse(profile);
if (!response.isSuccess()) {
String errorMsg =
String.format("Could not update customer from profile for %s",
profile.getUsername());
log.error(errorMsg);
throw new UnexpectedException(errorMsg);
}
} catch (Exception ex) {
// Throw AMQP exception and redeliver the message
throw new AmqpIllegalStateException("Customer service update failed", ex);
}
}
示例10: checkSupportingInfoRequirement
import org.springframework.amqp.rabbit.annotation.RabbitListener; //导入依赖的package包/类
/**
* Determine what supporting information is required from the archvies
* @param submission
*/
@RabbitListener(queues = Queues.SUBMISSION_SUBMITTED_CHECK_SUPPORTING_INFO)
public void checkSupportingInfoRequirement(Submission submission) {
logger.info("checkSupportingInfoRequirement {}", submission);
Map<Archive,SubmissionEnvelope> submissionEnvelopesForArchives = dispatcherService.determineSupportingInformationRequired(submission);
if (!submissionEnvelopesForArchives.containsKey(Archive.BioSamples)){
return;
}
//TODO only handles BioSamples
SubmissionEnvelope submissionEnvelope = submissionEnvelopesForArchives.get(Archive.BioSamples);
if (submissionEnvelope.getSupportingSamplesRequired().isEmpty()){
return;
}
rabbitMessagingTemplate.convertAndSend(
Exchanges.SUBMISSIONS,
Topics.EVENT_SUBMISSION_NEEDS_SAMPLES,
submissionEnvelope
);
}
示例11: handleSampleUpdate
import org.springframework.amqp.rabbit.annotation.RabbitListener; //导入依赖的package包/类
@RabbitListener(queues = Queues.ENA_SAMPLES_UPDATED)
public void handleSampleUpdate(UpdatedSamplesEnvelope updatedSamplesEnvelope){
logger.info("received updated samples for submission {}",updatedSamplesEnvelope.getSubmissionId());
updatedSamplesEnvelope.getUpdatedSamples().forEach( s ->{
if (s.getAccession() == null) return;
Sample knownSample = enaSampleRepository.findByAccession(s.getAccession());
if (knownSample == null) return;
enaSampleRepository.save(s);
logger.debug("updates sample {} using submission {}",s.getAccession(),updatedSamplesEnvelope.getSubmissionId());
});
logger.info("finished updating samples for submission {}", updatedSamplesEnvelope.getSubmissionId());
}
示例12: handleSamplesSubmission
import org.springframework.amqp.rabbit.annotation.RabbitListener; //导入依赖的package包/类
@RabbitListener(queues = Queues.BIOSAMPLES_AGENT)
public void handleSamplesSubmission(SubmissionEnvelope envelope) {
Submission submission = envelope.getSubmission();
logger.info("Received submission {}", submission.getId());
// Process samples
List<ProcessingCertificate> certificatesCompleted = samplesProcessor.processSamples(envelope);
ProcessingCertificateEnvelope certificateEnvelopeCompleted = new ProcessingCertificateEnvelope(
submission.getId(),
certificatesCompleted
);
rabbitMessagingTemplate.convertAndSend(Exchanges.SUBMISSIONS, Topics.EVENT_SUBMISSION_AGENT_RESULTS, certificateEnvelopeCompleted);
logger.info("Processed submission {}", submission.getId());
}
示例13: save
import org.springframework.amqp.rabbit.annotation.RabbitListener; //导入依赖的package包/类
@RabbitListener(bindings = @QueueBinding(
value = @Queue,
exchange = @Exchange(value = "learning-spring-boot"),
key = "comments.new"
))
public void save(Comment newComment) {
repository
.save(newComment)
.log("commentService-save")
.subscribe();
}
示例14: dummyShipGoodsCommand
import org.springframework.amqp.rabbit.annotation.RabbitListener; //导入依赖的package包/类
/**
* Dummy method to handle the shipGoods command message - as we do not have a
* shipping system available in this small example
*/
@RabbitListener(bindings = @QueueBinding( //
value = @Queue(value = "shipping_create_test", durable = "true"), //
exchange = @Exchange(value = "shipping", type = "topic", durable = "true"), //
key = "*"))
@Transactional
public void dummyShipGoodsCommand(String orderId) {
// and call back directly with a generated transactionId
handleGoodsShippedEvent(orderId, UUID.randomUUID().toString());
}
开发者ID:berndruecker,项目名称:camunda-spring-boot-amqp-microservice-cloud-example,代码行数:14,代码来源:AmqpReceiver.java
示例15: customerWorker
import org.springframework.amqp.rabbit.annotation.RabbitListener; //导入依赖的package包/类
@RabbitListener(queues = "customer-command-queue")
public void customerWorker(Message message) {
try {
log.info("customerWorker; accepted message: {}", message);
Customer saved = customerService.save(toCustomer(message));
log.debug("customerWorker; saved value: {}", saved);
} catch (Exception e) {
log.error("{}", e);
}
}