Created
October 6, 2013 17:40
-
-
Save willemsst/6856884 to your computer and use it in GitHub Desktop.
akka james-smtp camel actor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package be.idevelop.opencom.smtp.server.actor; | |
import akka.actor.*; | |
import akka.camel.*; | |
import akka.camel.javaapi.*; | |
import org.apache.camel.*; | |
import org.apache.camel.component.james.smtp.*; | |
import org.slf4j.*; | |
import scala.concurrent.duration.*; | |
import java.util.concurrent.*; | |
public class SmtpActor extends UntypedConsumerActor { | |
private final static FiniteDuration timeout = Duration.create(1, TimeUnit.SECONDS); | |
private static final String SMTP = "smtp"; | |
private Logger logger = LoggerFactory.getLogger(SmtpActor.class); | |
protected SmtpActor() { | |
} | |
public static Props create(ActorSystem system) { | |
Camel camel = CamelExtension.get(system); | |
CamelContext camelContext = camel.context(); | |
if (camelContext.hasComponent(SMTP) == null) { | |
SMTPComponent component = new SMTPComponent(); | |
camelContext.addComponent(SMTP, component); | |
} | |
return Props.apply(SmtpActor.class); | |
} | |
@Override | |
public void onReceive(Object message) throws Exception { | |
if (message instanceof CamelMessage) { | |
logger.info("SMTP actor received {}", message); | |
getSender().tell(Ack.getInstance(), self()); | |
} else { | |
unhandled(message); | |
} | |
} | |
@Override | |
public FiniteDuration replyTimeout() { | |
return timeout; | |
} | |
@Override | |
public boolean autoAck() { | |
return false; | |
} | |
@Override | |
public String getEndpointUri() { | |
return "smtp:all:25052"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment