Search in sources :

Example 1 with MessageSender

use of org.hisp.dhis.message.MessageSender in project dhis2-core by dhis2.

the class ServiceConfig method defaultOutboundMessageBatchService.

@Bean("org.hisp.dhis.outboundmessage.OutboundMessageService")
public DefaultOutboundMessageBatchService defaultOutboundMessageBatchService(SmsMessageSender smsMessageSender, EmailMessageSender emailMessageSender) {
    Map<DeliveryChannel, MessageSender> channels = new HashMap<>();
    channels.put(DeliveryChannel.SMS, smsMessageSender);
    channels.put(DeliveryChannel.EMAIL, emailMessageSender);
    DefaultOutboundMessageBatchService service = new DefaultOutboundMessageBatchService();
    service.setMessageSenders(channels);
    return service;
}
Also used : DefaultOutboundMessageBatchService(org.hisp.dhis.outboundmessage.DefaultOutboundMessageBatchService) DeliveryChannel(org.hisp.dhis.common.DeliveryChannel) HashMap(java.util.HashMap) MessageSender(org.hisp.dhis.message.MessageSender) SmsMessageSender(org.hisp.dhis.sms.config.SmsMessageSender) EmailMessageSender(org.hisp.dhis.message.EmailMessageSender) Bean(org.springframework.context.annotation.Bean)

Example 2 with MessageSender

use of org.hisp.dhis.message.MessageSender in project dhis2-core by dhis2.

the class DefaultOutboundMessageBatchService method send.

// ---------------------------------------------------------------------
// Supportive Methods
// ---------------------------------------------------------------------
private OutboundMessageResponseSummary send(OutboundMessageBatch batch) {
    DeliveryChannel channel = batch.getDeliveryChannel();
    MessageSender sender = messageSenders.get(channel);
    if (sender == null) {
        String errorMessage = String.format("No server/gateway found for delivery channel %s", channel);
        log.error(errorMessage);
        return new OutboundMessageResponseSummary(errorMessage, channel, OutboundMessageBatchStatus.FAILED);
    } else if (!sender.isConfigured()) {
        String errorMessage = String.format("Server/gateway for delivery channel %s is not configured", channel);
        log.error(errorMessage);
        return new OutboundMessageResponseSummary(errorMessage, channel, OutboundMessageBatchStatus.FAILED);
    }
    log.info("Invoking message sender: " + sender.getClass().getSimpleName());
    return sender.sendMessageBatch(batch);
}
Also used : DeliveryChannel(org.hisp.dhis.common.DeliveryChannel) MessageSender(org.hisp.dhis.message.MessageSender)

Aggregations

DeliveryChannel (org.hisp.dhis.common.DeliveryChannel)2 MessageSender (org.hisp.dhis.message.MessageSender)2 HashMap (java.util.HashMap)1 EmailMessageSender (org.hisp.dhis.message.EmailMessageSender)1 DefaultOutboundMessageBatchService (org.hisp.dhis.outboundmessage.DefaultOutboundMessageBatchService)1 SmsMessageSender (org.hisp.dhis.sms.config.SmsMessageSender)1 Bean (org.springframework.context.annotation.Bean)1