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

时间:2017-09-11 22:27:02

标签: logging jms activemq wildfly-10

我正在复制一个与WildFly 8 / HornetMQ / Log4J配合使用的旧应用程序。它是一个远程Java GUI客户端,它使用JMS ObjectMessages。

到目前为止,一切都在为WildFly 10 / ActiveMQ / Slf4j重新配置时再次运行,除了一件事:

在我的MDB收到ObjectMessage(其Object是一个ArrayList)后,当MDB在消息上调用getObject()时,它会抛出JMSException错误。 JMSExcetion。 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日志记录,则一切正常...除了我之外,我无法从MDM从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的所有子类中没有使用所有记录器:

@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);
  }

}

1 个答案:

答案 0 :(得分:2)

制作记录器变量transient,我并不是指@Transient