【发布时间】:2017-09-26 03:55:28
【问题描述】:
我正在恢复使用 WildFly 8 / HornetMQ / Log4J 的旧应用程序。它是一个交换 JMS ObjectMessages 的远程 Java GUI 客户端。
到目前为止,当为 WildFly 10 / ActiveMQ / Slf4j 重新配置时,一切都恢复正常,除了一件事:
在我的 MDB 收到一个 ObjectMessage(其对象是一个 ArrayList)后,当 MDB 对该消息调用 getObject() 时,它会引发 JMSException 错误。 JMS 异常。 e.getMessage() 返回:
org.slf4j.log4j12.Log4jLoggerAdapter from
[Module "org.apache.activemq.artemis:main" from local module loader @1c2c22f3
(finder: local module finder @18e8568
(roots: C:\ProgramFilesGeo\Wildfly\wildfly-10.1.0.Final\modules,
C:\ProgramFilesGeo\Wildfly\wildfly-10.1.0.Final\modules\system\layers\base)
但是,如果我从 ArrayList 中的 EntityParent 实例中删除 Slf4J 日志记录,则一切正常……除了我无法从 MDB 从 ObjectMessage 中提取的 EntityParent 子类中记录日志。
这是我目前所知道的:
这显然是 Slf4j 的问题,我猜是序列化。因为否则,Slf4j 在服务器端可以正常工作。我的意思是上面的消息是用 MDB 中的这个记录器代码写入 WF 日志的:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final Logger logger = Logger.getLogger(GoMsgBean.class.getName());
我的 MDB 确认消息到达如下: 活动MQObjectMessage
在传输 ObjectMessage 之前,我测试了 EntityParent 的实例和用于序列化的 ArrayList - 能力:
new ObjectOutputStream(new ByteArrayOutputStream()).writeObject(each of the above objects separately);
网络搜索找到了我的问题的一个匹配项——getObject() 抛出了 JMSException。但它被标记为未回答。而且所发布的内容都包含在对代理服务器和类加载器的讨论中,以至于没有帮助。
我发现了与 Log4j 记录器相关的其他讨论。他们建议将记录器注释为@Transient。但随后声称切换到 slf4j “解决了”这个问题,而没有使其成为 @Transient。所以我都切换到 slf4j 并将其标记为@Transient。没有使用 ArrayList 中 EntityParent 的所有子类中的所有记录器:
@Transient
final Logger logger = LoggerFactory.getLogger(LoggedIn.class);
slf4j 网站讨论了其他问题,但它们似乎都涉及应用程序尝试保留 log4j 日志记录的情况。不再是我的情况了。
所以我希望有人能提供帮助,因为我不知道还能去哪里找……我真正的工作是在 MDB 可以提取实体后处理数据库。
如果有什么用,这里是standalone-full.xml的activeMQ子系统
<subsystem xmlns="urn:jboss:domain:messaging-activemq:1.0">
<server name="default">
<security enabled="false"/>
<security-setting name="#">
<role name="guest" send="true" consume="true" create-non-durable-queue="true" delete-non-durable-queue="true"/>
</security-setting>
<address-setting name="#" dead-letter-address="jms.queue.DLQ" expiry-address="jms.queue.ExpiryQueue" max-size-bytes="10485760" page-size-bytes="2097152" message-counter-history-day-limit="10"/>
<http-connector name="http-connector" socket-binding="http" endpoint="http-acceptor"/>
<http-connector name="http-connector-throughput" socket-binding="http" endpoint="http-acceptor-throughput">
<param name="batch-delay" value="50"/>
</http-connector>
<in-vm-connector name="in-vm" server-id="0"/>
<http-acceptor name="http-acceptor" http-listener="default"/>
<http-acceptor name="http-acceptor-throughput" http-listener="default">
<param name="batch-delay" value="50"/>
<param name="direct-deliver" value="false"/>
</http-acceptor>
<in-vm-acceptor name="in-vm" server-id="0"/>
<jms-queue name="ExpiryQueue" entries="java:/jms/queue/ExpiryQueue"/>
<jms-queue name="DLQ" entries="java:/jms/queue/DLQ"/>
<jms-queue name="SendToServerQueue" entries="java:jboss/exported/jms/queue/sendToServerQueue java:/jms/queue/sendToServerQueue"/>
<jms-queue name="SendToClientQueue2" entries="java:jboss/exported/jms/queue/sendToClientQueue2"/>
<connection-factory name="InVmConnectionFactory" entries="java:/ConnectionFactory" connectors="in-vm"/>
<connection-factory name="RemoteConnectionFactory" entries="java:jboss/exported/jms/RemoteConnectionFactory" connectors="http-connector"/>
<pooled-connection-factory name="activemq-ra" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" connectors="in-vm" transaction="xa"/>
</server>
</subsystem>
这是为赏金添加的:它是我当前 JPA 实体 (POJO) 类的副本。它完美地工作,所有日志都被注释掉了。但是当重新添加 slf4j 记录器时,它会因上述错误而失败。即使 slf4j 记录器对 MDB 和会话 Bean 工作正常,我还是使用 ear 包进行部署。
package org.america3.gotest.shared.jpa;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.america3.gotest.shared.interfaces.DataItemKeyValues;
import org.america3.gotest.shared.tools.Utility;
@NamedQueries(
{@NamedQuery(name="LoggedIn.findLoggedInbyId",
query = "SELECT li " +
"From LoggedIn li " +
"WHERE li.memberId = :memberIdP"),
@NamedQuery(name="findLoggedInByAll",
query = "DELETE FROM LoggedIn li " +
"WHERE li.memberId = :memberIdP " +
"AND li.memberPw = :memberPwP " +
"AND li.clientHash = clientHashP")
})
@Entity(name="LoggedIn")
@Table(name="loggedins")
public class LoggedIn extends EntityParent implements Serializable, DataItemKeyValues {
/* See EntityParent for explanation of 9 fields
* This subclass only persists memberId, memberPW, and clientHash
*/
//@Transient
//final Logger logger = LoggerFactory.getLogger(LoggedIn.class);
//constructors
public LoggedIn() {
this.setMemberId(NOT_APPLICABLE);
this.setMemberPw(NOT_APPLICABLE);
this.SetClientHash(NOT_APPLICABLE);
this.setClientUserId(NOT_APPLICABLE);
this.setClientUserPw(NOT_APPLICABLE);
this.setOwnerId(NOT_APPLICABLE);
this.setOwnerPw(NOT_APPLICABLE);
this.setOpponentId(NOT_APPLICABLE);
this.setOpponentPw(NOT_APPLICABLE);
};
public LoggedIn(String hash, String id, String pw) {
this();
if (id != null && pw !=null && hash != null) {
this.setMemberId(id);
this.setMemberPw(pw);
this.SetClientHash(hash);
} else {
//logger.error("Log in was attempted with: id \"" + id + "\" pw \"" + hash + "\"");
String iAmM = Utility.getIAmM(Thread.currentThread().getStackTrace());
System.err.println(iAmM + "Log in was attempted with: id \"" + id + "\" pw \"" + hash + "\"");
}
}
public LoggedIn(EntityParent loggedIn) {
this();
this.memberId = loggedIn.getMemberId();
this.memberPw = loggedIn.getMemberPw();
this.clientHash = loggedIn.getClientHash();
}
// persisted fields
@Id @Column(name="PK")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer pk;
@Column(name="MBR_ID")
private String memberId;
@Column(name="MBR_PW")
private String memberPw;
@Column(name="HASH")
private String clientHash;
// Transient fields
@Transient
private String clientUserId;
@Transient
private String clientUserPw;
@Transient
private String ownerId;
@Transient
private String ownerPw;
@Transient
private String opponentId;
@Transient
private String opponentPw;
private static final long serialVersionUID = 1L;
// get set methods
public Integer getPk () {return this.pk;}
public void setPk (Integer pk) {this.pk = pk;}
public String getMemberId () {return memberId;}
public void setMemberId (String memberId) {this.memberId = (memberId == null? "" : memberId);}
public String getMemberPw () {return this.memberPw;}
public void setMemberPw (String memberPw) {this.memberPw = (memberPw == null? "" : memberPw);}
public String getClientHash () {return clientHash;}
public void SetClientHash (String clientHash) {this.clientHash = (clientHash == null? "" : clientHash);}
public boolean equals (LoggedIn otherLoggedIn) {
if (otherLoggedIn == null) return false;
if (this.pk == otherLoggedIn.getPk()) {
return true;
} else {
return false;
}
}
// other methods
@Transient
public String getClientUserId () {return this.clientUserId;}
public void setClientUserId (String clientUserId) {this.clientUserId = (clientUserId == null? "" : clientUserId);}
@Transient
public String getClientUserPw () {return this.clientUserPw;}
public void setClientUserPw (String clientUserPw) {this.clientUserPw = (clientUserPw == null? "" : clientUserPw);}
@Transient
public String getOwnerId () {return this.ownerId;}
public void setOwnerId (String ownerId) {this.ownerId = (ownerId == null? "" : ownerId);}
@Transient
public String getOwnerPw () {return ownerPw;}
public void setOwnerPw (String ownerPw) {this.ownerPw = (ownerPw == null? "" : ownerPw);}
@Transient
public String getOpponentId () {return opponentId;}
public void setOpponentId (String opponentId) {this.opponentId = (opponentId == null? "" : opponentId);}
@Transient
public String getOpponentPw () {return opponentPw;}
public void setOpponentPw (String opponentPw) {this.opponentPw = (opponentPw == null? "" : opponentPw);}
public void writeEntity () {
//String iAmS = Utility.getIAmS(Thread.currentThread().getStackTrace());
//logger.info(iAmS + this.getClass().getSimpleName() + " contains these values");
//logger.info(iAmS + " PK (pk) : " + this.pk);
//logger.info(iAmS + " MBR_ID (memberId) : " + this.memberId);
//logger.info(iAmS + " MBR_PW (memberPw) : " + this.memberPw);
//logger.info(iAmS + " HASH (clientHash) : " + this.clientHash);
//logger.info(iAmS + " Trans (clientUserId): " + this.clientUserId);
//logger.info(iAmS + " Trans (clientUserPw): " + this.clientUserPw);
}
}
【问题讨论】:
-
您是否在部署中排除了日志子系统或日志依赖项?
-
-
- -
Opps ... 上面的评论在我提到之前就消失了,我在部署时发现了一个内置到 .ear 的 META-INFO 文件夹中的 module.xml 工件。以上就是这样。不知道如何在这些 cmets 中格式化 CODE。但是我删除了它并且......没有变化。 getObject() 上的相同错误。否则,我不会故意在我的部署中添加依赖项。其他内置到 ear 中的 xml 文件是 application.xml 和 persistance.xml,它们都不是地址日志记录。
-
我在 [wildfly-10.1.0.Final\modules\system\layers\base\org\jboss\logging\main\module.xml]
...(我要去了解如何使代码看起来像代码) -
对不起......这只是一个测试我只能尝试一个真正的评论:'line 1 line2 line 3'? Post 说 back tic 会格式化代码。但似乎没有
标签: logging jms activemq wildfly-10