JCA Outbond MessageEndpoint размер

Я хочу отправить несколько исходящих сообщений с помощью моего собственного исходящего адаптера JCA на сервере приложений Liberty.

это мой адаптер ресурсов:

@Connector(description = "Example Resource Adapter", displayName = "Example Resource Adapter", eisType = "Example Resource Adapter", version = "1.0")
public class ExampleResourceAdapter implements ResourceAdapter {

    private EndpointTarget endpointTarget;
    private MessageEndpointFactory messageEndpointFactory;

    public void start(BootstrapContext bootstrapContext) {
    }

    public void stop() {
    }

    public void endpointActivation(final MessageEndpointFactory messageEndpointFactory, final ActivationSpec activationSpec) {
        this.messageEndpointFactory = messageEndpointFactory;
    }

    public void endpointDeactivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) {
        if (endpointTarget != null) {
            endpointTarget.getMessageEndpoint().release();
        }
    }

    public XAResource[] getXAResources(ActivationSpec[] activationSpecs) {
        return new XAResource[0];
    }

    public void executeRequest(String iid) {
        endpointTarget = new EndpointTarget(messageEndpointFactory, iid);
        endpointTarget.start();
    }      

и это управляемое соединение jca:

public class ExampleManagedConnection implements ManagedConnection {

    private static Logger log = Logger.getLogger(ExampleManagedConnection.class.getName());

    private PrintWriter logwriter;

    private ExampleManagedConnectionFactory mcf;

    private List<ConnectionEventListener> listeners;

    private ExampleConnectionImpl connection;

    public ExampleManagedConnection(ExampleManagedConnectionFactory mcf) {
        this.mcf = mcf;
        this.logwriter = null;
        this.listeners = Collections.synchronizedList(new ArrayList<>(1));
        this.connection = null;
    }

    public Object getConnection(Subject subject,
                                ConnectionRequestInfo cxRequestInfo) throws ResourceException {
        log.finest("getConnection()");
        connection = new ExampleConnectionImpl(this, mcf);
        return connection;
    }

    public void associateConnection(Object connection) throws ResourceException {
        log.finest("associateConnection()");

        if (connection == null)
            throw new ResourceException("Null connection handle");

        if (!(connection instanceof ExampleConnectionImpl))
            throw new ResourceException("Wrong connection handle");

        this.connection = (ExampleConnectionImpl) connection;
    }

    public void cleanup() throws ResourceException {
        log.finest("cleanup()");
    }

    public void destroy() throws ResourceException {
        log.finest("destroy()");
    }

    public void addConnectionEventListener(ConnectionEventListener listener) {
        log.finest("addConnectionEventListener()");

        if (listener == null) {
            throw new IllegalArgumentException("Listener is null");
        }

        listeners.add(listener);
    }

    public void removeConnectionEventListener(ConnectionEventListener listener) {
        log.finest("removeConnectionEventListener()");
        if (listener == null)
            throw new IllegalArgumentException("Listener is null");
        listeners.remove(listener);
    }

    public PrintWriter getLogWriter() throws ResourceException {
        log.finest("getLogWriter()");
        return logwriter;
    }

    public void setLogWriter(PrintWriter out) throws ResourceException {
        log.finest("setLogWriter()");
        logwriter = out;
    }

    public LocalTransaction getLocalTransaction() throws ResourceException {
        throw new NotSupportedException("getLocalTransaction() not supported");
    }

    public XAResource getXAResource() throws ResourceException {
        throw new NotSupportedException("getXAResource() not supported");
    }

    public ManagedConnectionMetaData getMetaData() throws ResourceException {
        log.finest("getMetaData()");
        return new ExampleManagedConnectionMetaData();
    }

    public void getPreTimeMarketOrders(String iid) {
        ExampleResourceAdapter ExampleResourceAdapter = (ExampleResourceAdapter) mcf.getResourceAdapter();
        ExampleResourceAdapter.executeRequest(iid);
    }
}     

я получаю это исключение при отправке более 500 запросов:

javax.resource.spi.RetryableUnavailableException: limit for number of MessageEndpoint proxies reached.  Limit = 500
at com.ibm.ws.ejbcontainer.mdb.BaseMessageEndpointFactory.createEndpoint(BaseMessageEndpointFactory.java:349)
at com.ibm.ws.ejbcontainer.mdb.internal.MessageEndpointFactoryImpl.createEndpoint(MessageEndpointFactoryImpl.java:385)   

Как изменить пул потоков адаптера JCA в сервере приложений Liberty/OpenLiberty?


person mah454    schedule 17.02.2021    source источник


Ответы (1)


Глядя на исходный код OpenLiberty, 500 — это значение по умолчанию, которое используется в отсутствие другой конфигурации.

Похоже, вы можете настроить другой максимальный размер пула для типа компонента. См. раздел, посвященный com.ibm.websphere.ejbcontainer.poolSize, в этот документ.

Тем не менее, ваш подход кажется немного нетрадиционным, поскольку MessageEndpointFactory предназначен для входящей, а не исходящей связи. Для входящей связи используется Message Driven Bean для получения входящих сообщений (для которого может быть настроен размер com.ibm.websphere.ejbcontainer.poolSize).

Ваш подход к перезаписыванию endpointTarget внутри executeRequest также вызывает подозрения. @Connector/ResourceAdapter класс ExampleResourceAdapter является одноэлементным, поэтому, если у вас есть перекрывающиеся executeRequest, он перезапишет endpointTarget, и только один из них будет выпущен в endpointDeactivation.

person njr    schedule 17.02.2021
comment
Спасибо, я отправляю параллельный запрос, поэтому не могу перезаписать endpointTarget. - person mah454; 17.02.2021