View Javadoc
1   package org.nhindirect.gateway.streams;
2   
3   import java.util.HashMap;
4   import java.util.Map;
5   
6   import org.nhindirect.common.mail.SMTPMailMessage;
7   import org.nhindirect.common.mail.streams.SMTPMailMessageConverter;
8   import org.springframework.beans.factory.annotation.Autowired;
9   import org.springframework.beans.factory.annotation.Qualifier;
10  import org.springframework.cloud.stream.annotation.EnableBinding;
11  import org.springframework.cloud.stream.annotation.Output;
12  import org.springframework.messaging.Message;
13  import org.springframework.messaging.MessageChannel;
14  
15  @EnableBinding(SmtpRemoteDeliveryOutput.class)
16  public class SmtpRemoteDeliverySource
17  {
18  	public static final String REMOTE_DELIVERY_GROUPED = "REMOTE_DELIVERY_GROUPED";	
19  	
20  	@Autowired
21  	@Qualifier(SmtpRemoteDeliveryOutput.SMTP_REMOTE_DELIVERY_MESSAGE_OUTPUT)
22  	private MessageChannel remoteDeliveryChannel;
23  	
24  	@Output(SmtpRemoteDeliveryOutput.SMTP_REMOTE_DELIVERY_MESSAGE_OUTPUT)
25  	public <T> void remoteDelivery(SMTPMailMessage msg, boolean grouped) 
26  	{
27  		final Map<String, Object> headerMap = new HashMap<>();
28  		headerMap.put(REMOTE_DELIVERY_GROUPED, true);
29  		
30  		final Message<?> streamMsg = (!grouped) ? SMTPMailMessageConverter.toStreamMessage(msg) :
31  			SMTPMailMessageConverter.toStreamMessage(msg, headerMap);
32  		
33  		this.remoteDeliveryChannel.send(streamMsg);
34  
35  	}
36  }