gpt4 book ai didi

logging - 为什么 slf4j w/Wildfly ActiveMQ 会导致 ObjectMessage.getMessage() 抛出 JMSException?

转载 作者:行者123 更新时间:2023-12-02 01:08:51 25 4
gpt4 key购买 nike

我正在复活一个与 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 确认消息到达如下:ActiveMQObjectMessage

在传输 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 和 session 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);
}

}

最佳答案

使记录器变量transient,我不是说@Transient

关于logging - 为什么 slf4j w/Wildfly ActiveMQ 会导致 ObjectMessage.getMessage() 抛出 JMSException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46165174/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com