Search in sources :

Example 46 with TransactionAttribute

use of javax.ejb.TransactionAttribute in project UVMS-ExchangeModule-APP by UnionVMS.

the class ExchangeConsumerBean method getMessage.

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
@Override
public <T> T getMessage(String correlationId, Class type) throws ExchangeMessageException {
    if (correlationId == null || correlationId.isEmpty()) {
        LOG.error("[ No CorrelationID provided when listening to JMS message, aborting ]");
        throw new ExchangeMessageException("No CorrelationID provided!");
    }
    Connection connection = null;
    try {
        connection = connectionFactory.createConnection();
        final Session session = JMSUtils.connectToQueue(connection);
        T response = (T) session.createConsumer(responseQueue, "JMSCorrelationID='" + correlationId + "'").receive(TIMEOUT);
        if (response == null) {
            throw new ExchangeMessageException("[ Timeout reached or message null in ExchangeConsumerBean. ]");
        }
        return response;
    } catch (Exception e) {
        LOG.error("[ Error when getting message ] {}", e.getMessage());
        throw new ExchangeMessageException("Error when retrieving message: ");
    } finally {
        JMSUtils.disconnectQueue(connection);
    }
}
Also used : ExchangeMessageException(eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException) ExchangeMessageException(eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException) ConfigMessageException(eu.europa.ec.fisheries.uvms.config.exception.ConfigMessageException) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 47 with TransactionAttribute

use of javax.ejb.TransactionAttribute in project UVMS-ExchangeModule-APP by UnionVMS.

the class ExchangeMessageProducerBean method sendEventBusMessage.

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public String sendEventBusMessage(String text, String serviceName) throws ExchangeMessageException {
    Connection connection = null;
    try {
        LOG.debug("Sending event bus message from Exchange module to recipient om JMS Topic to: {} ", serviceName);
        connection = connectionFactory.createConnection();
        final Session session = JMSUtils.connectToQueue(connection);
        TextMessage message = session.createTextMessage();
        message.setText(text);
        message.setStringProperty(ExchangeModelConstants.SERVICE_NAME, serviceName);
        message.setJMSReplyTo(eventQueue);
        getProducer(session, eventBus).send(message);
        return message.getJMSMessageID();
    } catch (Exception e) {
        LOG.error("[ Error when sending message. ] ", e);
        throw new ExchangeMessageException("[ Error when sending message. ]");
    } finally {
        JMSUtils.disconnectQueue(connection);
    }
}
Also used : ExchangeMessageException(eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException) ExchangeModelMapperException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMapperException) ExchangeMessageException(eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException) ConfigMessageException(eu.europa.ec.fisheries.uvms.config.exception.ConfigMessageException) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 48 with TransactionAttribute

use of javax.ejb.TransactionAttribute in project UVMS-ExchangeModule-APP by UnionVMS.

the class ExchangeMessageProducerBean method sendMessageOnQueue.

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public String sendMessageOnQueue(String text, MessageQueue queue) throws ExchangeMessageException {
    Connection connection = null;
    try {
        connection = connectionFactory.createConnection();
        final Session session = JMSUtils.connectToQueue(connection);
        TextMessage message = session.createTextMessage();
        message.setJMSReplyTo(responseQueue);
        message.setText(text);
        switch(queue) {
            case EVENT:
                getProducer(session, eventQueue).send(message);
                break;
            case RULES:
                getProducer(session, rulesQueue).send(message);
                break;
            case CONFIG:
                getProducer(session, configQueue).send(message);
                break;
            case VESSEL:
                getProducer(session, vesselQueue).send(message);
                break;
            case SALES:
                getProducer(session, salesQueue).send(message);
                break;
            case AUDIT:
                getProducer(session, auditQueue).send(message);
                break;
            case ACTIVITY_EVENT:
                getProducer(session, activityQueue).send(message);
                break;
            case MDR_EVENT:
                getProducer(session, mdrQueue).send(message);
                break;
            case RULES_RESPONSE:
                getProducer(session, rulesResponseQueue).send(message);
                break;
            default:
                break;
        }
        return message.getJMSMessageID();
    } catch (Exception e) {
        LOG.error("[ Error when sending message. ]");
        throw new ExchangeMessageException("[ Error when sending message. ]");
    } finally {
        JMSUtils.disconnectQueue(connection);
    }
}
Also used : ExchangeMessageException(eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException) ExchangeModelMapperException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMapperException) ExchangeMessageException(eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException) ConfigMessageException(eu.europa.ec.fisheries.uvms.config.exception.ConfigMessageException) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 49 with TransactionAttribute

use of javax.ejb.TransactionAttribute in project quickstart by wildfly.

the class RemoteBeanCaller method remoteOutboundStatelessNoTxBeanCall.

/**
 * <p>
 * The method calls the remote EJB {@link Stateless} endpoint.
 * </p>
 * <p>
 * To lookup the remote endpoint is used remote outbound connection defined in the <code>standalone.xml</code> configuration file.
 * The deployment links to the configuration by descriptor <code>WEB-INF/jboss-ejb-client.xml</code>.
 * </p>
 *
 * <p>
 * The demonstration shows what happens when several subsequent calls are run while no transaction is started.
 * With one remote server all requests go to that one instance of <code>server2</code>.
 * It makes a difference if there are two (or more) remote servers clustered (<code>server2</code> is run in HA of more instances).
 * <br/>
 * There is defined no transaction context, the remote call should be load-balanced by EJB client
 * and the first call goes to the first remote server and the second call goes to the second remote server.
 * </p>
 *
 * @return list of strings as return values from the remote beans,
 *         in this case the return values are hostnames and the jboss node names of the remote application server
 * @throws NamingException when remote lookup fails
 */
@TransactionAttribute(value = TransactionAttributeType.NOT_SUPPORTED)
public List<String> remoteOutboundStatelessNoTxBeanCall() throws NamingException {
    log.debugf("Calling with outbound connection without transaction to StatelessBean.successOnCall()");
    RemoteBeanInterface bean = RemoteLookupHelper.lookupRemoteEJBOutbound("StatelessBean", RemoteBeanInterface.class, false);
    List<String> callResponses = new ArrayList<>();
    for (int i = 1; i <= 20; i++) {
        callResponses.add(bean.successOnCall());
    }
    return callResponses;
}
Also used : ArrayList(java.util.ArrayList) RemoteBeanInterface(org.jboss.as.quickstarts.ejb.server.RemoteBeanInterface) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 50 with TransactionAttribute

use of javax.ejb.TransactionAttribute in project quickstart by wildfly.

the class RemoteBeanCaller method remoteOutboundStatefulNoTxBeanCall.

/**
 * <p>
 * The method calls the remote EJB {@link javax.ejb.Stateful} endpoint.
 * </p>
 * <p>
 * To lookup the remote endpoint is used remote outbound connection defined in the <code>standalone.xml</code> configuration file.
 * The deployment links to the configuration by descriptor <code>WEB-INF/jboss-ejb-client.xml</code>.
 * </p>
 *
 * <p>
 * This demonstrates what happens on two subsequent calls to the stateful bean when no transaction is started.
 * In fact, for stateful bean the demonstrated behaviour makes no difference if the transaction is or is not started.
 * </p>
 * <p>
 * As there are processed two remote EJB invocations and we talk about stateful bean the EJB client has to ensure
 * that both calls ends at the same remote server.
 * The demonstration does not make much sense when there is started only one instance of the remote server (<code>server2</code>).
 * But in case there are two remote servers started (two instances of <code>server2</code> are run)
 * then the second EJB invocation has to be directed to the same server as the first one.
 * </p>
 *
 * @return list of strings as return values from the remote beans,
 *         in this case the return value are hostnames and the jboss node names of the remote application server
 * @throws NamingException when remote lookup fails
 */
@TransactionAttribute(value = TransactionAttributeType.NOT_SUPPORTED)
public List<String> remoteOutboundStatefulNoTxBeanCall() throws NamingException {
    log.debugf("Calling with outbound connection without transaction to StatefulBean.successOnCall()");
    RemoteBeanInterface bean = RemoteLookupHelper.lookupRemoteEJBOutbound("StatefulBean", RemoteBeanInterface.class, true);
    return Arrays.asList(bean.successOnCall(), bean.successOnCall());
}
Also used : RemoteBeanInterface(org.jboss.as.quickstarts.ejb.server.RemoteBeanInterface) TransactionAttribute(javax.ejb.TransactionAttribute)

Aggregations

TransactionAttribute (javax.ejb.TransactionAttribute)61 JMSException (javax.jms.JMSException)8 IOException (java.io.IOException)7 Connection (javax.jms.Connection)6 Session (javax.jms.Session)6 TextMessage (javax.jms.TextMessage)6 Query (javax.persistence.Query)5 Configuration (org.hibernate.cfg.Configuration)5 Dataset (edu.harvard.iq.dataverse.Dataset)4 ConfigMessageException (eu.europa.ec.fisheries.uvms.config.exception.ConfigMessageException)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 EJBException (javax.ejb.EJBException)4 Message (javax.jms.Message)4 MessageProducer (javax.jms.MessageProducer)4 DataFile (edu.harvard.iq.dataverse.DataFile)3 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)3 ExchangeMessageException (eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException)3 Properties (java.util.Properties)3 EntityManager (javax.persistence.EntityManager)3