Árvore de páginas

Versões comparadas

Chave

  • Esta linha foi adicionada.
  • Esta linha foi removida.
  • A formatação mudou.

...

Para que a Central de Notificação do Fluig invoque o aplicativo para enviar notificações, o aplicativo deve obrigatoriamente implementar a interface "com.totvs.technology.foundation.alert.sender.AlertSenderApp" da API de notificações. No cadastro do aplicativo, o JNDI informado deve ser o nome para fazer lookup desta implementação. Abaixo um exemplo  simples de implementação desta interfacecriar um MDB que ouve a fila registrada. Abaixo um exemplo simples de MDB:

Bloco de código
languagejava
@Statelesspackage com.fluig;
import java.io.Serializable;
import java.util.Map;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.EJB;
import javax.ejb.MessageDriven;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 * Esta é a classe que será chamada pela Central de Notificações para enviar
 * alertas por este aplicativo.
 */
@MessageDriven(name = "myappqueue/MySenderServiceAlertSenderSampleQueue", mappedName = "myapp/MySenderService"AlertSenderSampleQueue", activationConfig = {
		@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
		@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
		@ActivationConfigProperty(propertyName = "destination", propertyValue = "AlertSenderSampleQueue")
})
public class MySenderServiceBeanAlertSampleMDBBean implements AlertSenderAppMessageListener {
	private static final Logger log = LoggerFactory
			.getLogger(AlertSampleMDBBean.class);
	@EJB(lookup = TxtSenderService.JNDI_REMOTE_NAME)
	private TxtSenderService service;
	@Override
	@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
	public void send(final Long alertIdonMessage(final Message message) {
		if (message instanceof ObjectMessage) {
			final ObjectMessage msg = (ObjectMessage) message;
			try {
				final Serializable obj = msg.getObject();
				if (log.isDebugEnabled()) {
			
		/* Meu código de envio da notificação */
				log.debug("AlertSenderSampleQueue.onMessage - obj: " + obj);
				}
				service.sendAlert((Map<String, Object>) obj);
				if (log.isDebugEnabled()) {
					log.debug("AlertSenderSampleQueue.onMessage - FIM");
				}
			} catch (final JMSException ex) {
				log.error(ex.getMessage(), ex);
			}
		}
	}
}

Quando o usuário receber um alerta, a Central de Notificações vai validar se aquele usuário está configurado para receber notificações por este aplicativo. Caso esteja, a Central invocará o método "send()", através do lookup do JNDI cadastrado postará uma mensagemna fila cadastrada para o aplicativo.

Desabilitando aplicativos de envio de Notificações:

...