Skip to content

Instantly share code, notes, and snippets.

@willemsst
Created October 6, 2013 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willemsst/6856884 to your computer and use it in GitHub Desktop.
Save willemsst/6856884 to your computer and use it in GitHub Desktop.
akka james-smtp camel actor
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