如何解决JCA Outbond MessageEndpoint 大小
我想在 Liberty 应用服务器上使用我自己的自定义 JCA 出站适配器发送多条出站消息。
这是我的资源适配器:
@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)
如何在 Liberty/OpenLiberty Application Server 中更改 JCA 适配器线程池?
解决方法
查看 OpenLiberty 源代码,500 是默认值,在没有其他配置的情况下使用。
看起来您可以为 bean 类型配置不同的最大池大小。请参阅 this document 中涵盖 com.ibm.websphere.ejbcontainer.poolSize
的部分。
也就是说,您的方法似乎有点不合常规,因为 MessageEndpointFactory 用于入站通信,而不是出站通信。入站通信涉及接收入站消息的消息驱动 Bean(可以为其配置 com.ibm.websphere.ejbcontainer.poolSize)。
您在 endpointTarget
中覆盖 executeRequest
的方法也很可疑。 @Connector
/ResourceAdapter
class ExampleResourceAdapter
是一个单例,所以如果你有重叠的 executeRequest
它会覆盖 endpointTarget
并且只有其中一个会在 {{ 1}}。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。