當前位置: 首頁>>代碼示例>>Java>>正文


Java RabbitListener類代碼示例

本文整理匯總了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();
		});
}
 
開發者ID:PacktPublishing,項目名稱:Learning-Spring-Boot-2.0-Second-Edition,代碼行數:16,代碼來源:CommentService.java

示例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);
    }

}
 
開發者ID:capesonlee,項目名稱:tangtang-spring-cloud,代碼行數:18,代碼來源:AmqpReciver.java

示例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;
}
 
開發者ID:TraineeSIIp,項目名稱:PepSIIrup-2017,代碼行數:26,代碼來源:EventController.java

示例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);
}
 
開發者ID:osmmosques,項目名稱:osm-mosques,代碼行數:23,代碼來源:OsmDataImporterHandler.java

示例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;
}
 
開發者ID:TraineeSIIp,項目名稱:PepSIIrup-2017,代碼行數:24,代碼來源:EventController.java

示例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;
}
 
開發者ID:TraineeSIIp,項目名稱:PepSIIrup-2017,代碼行數:26,代碼來源:EventController.java

示例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;
}
 
開發者ID:TraineeSIIp,項目名稱:PepSIIrup-2017,代碼行數:25,代碼來源:PersonController.java

示例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;
}
 
開發者ID:TraineeSIIp,項目名稱:PepSIIrup-2017,代碼行數:28,代碼來源:SuggestionController.java

示例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);
    }
}
 
開發者ID:kbastani,項目名稱:cloud-native-microservice-strangler-example,代碼行數:22,代碼來源:Receiver.java

示例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
    );

}
 
開發者ID:EMBL-EBI-SUBS-OLD,項目名稱:subs,代碼行數:30,代碼來源:DispatcherRabbitBridge.java

示例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());
}
 
開發者ID:EMBL-EBI-SUBS-OLD,項目名稱:subs,代碼行數:18,代碼來源:EnaAgentSubmissionsProcessor.java

示例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());
}
 
開發者ID:EMBL-EBI-SUBS-OLD,項目名稱:subs,代碼行數:17,代碼來源:Listener.java

示例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();
}
 
開發者ID:PacktPublishing,項目名稱:Learning-Spring-Boot-2.0-Second-Edition,代碼行數:12,代碼來源:CommentService.java

示例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);
    }
}
 
開發者ID:Rustam-Kadyrov,項目名稱:microservices-spring,代碼行數:11,代碼來源:QueueListener.java


注:本文中的org.springframework.amqp.rabbit.annotation.RabbitListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。