문제

다른 MessageConverter를 포장 할 수있는 MessageConverter 클래스를 작성하고 싶습니다. 이 MessageConverter는 자식 변환기를 호출하여 TextMessage를 생성하는 것으로 가정합니다. 페이로드와 gzip 압축이 필요하므로 바이트 메스저가 발생하여 궁극적으로 발신자에게 반환됩니다.

문제는 FromMessage ()를 서면으로 작성하는 것입니다. 페이로드를 문자열로 다시 변환 할 수는 있지만 문자열을 채우기 위해 "더미"텍스트 메시지를 만들고 싶습니다. JMS 세션 객체없이 TextMessage를 만들 수 없기 때문에 벽돌 벽을 치고 있습니다.이 맥락에서 세션을 얻을 방법이 전혀없는 것으로 보입니다.

이 클래스에 더 많은 것들을 연결하기 위해 추가 속성을 만들 수 있었지만 JMStemplate 객체에서 세션을 쉽게 얻을 수있는 것처럼 보이지 않으며, 내가 필요한 것이 무엇인지 상상할 수 없습니다.

나는 Child MessageConverter의 문자열을 포장하기 위해이 코드 내에서 개인 TextMessage 구현을 만들기 직전입니다. 그 수업은 인터페이스를 살리기 위해서는 수많은 더미 방법이 필요하며, 그 모든 타이핑은 아기 예수를 울게 만듭니다.

누구든지 더 나은 방법을 제안 할 수 있습니까?

도움이 되었습니까?

해결책 2

사실, 나는 이것들 중 하나를 만들었습니다.

    private static class FakeTextMessage implements TextMessage {
            public FakeTextMessage(Message m) { this.childMessage = m; }
            private String text;
            private Message childMessage;
            public void setText(String t) { this.text = t; }
            public String getText() { return this.text; }

            // All the rest of the methods are simply pass-through
            // implementations of the rest of the interface, handing off to the child message.
            public void acknowledge() throws JMSException { this.childMessage.acknowledge(); }
            public void clearBody() throws JMSException { this.childMessage.clearBody(); }
            public void clearProperties() throws JMSException { this.childMessage.clearProperties(); }
            public Enumeration getPropertyNames() throws JMSException { return this.childMessage.getPropertyNames(); }
            public boolean propertyExists(String pn) throws JMSException { return this.childMessage.propertyExists(pn); }

            // and so on and so on
    }

객관적인 C에 오랜 시간이 걸립니다. 어떻게 가능합니까? :)

다른 팁

다른 MessageConverter 인스턴스 안에 MessageConverter 인스턴스를 정말로 랩하고 싶습니까? MessageConverter의 요점은 메시지를 다른 것으로 바꾸는 것입니다 (JMS 메시지가 아닙니다). 그것은 실제로 그들을 사슬로 설계되지 않았습니다 (각 단계에서 가짜 JMS 메시지를 만듭니다).

자신의 인터페이스를 소개하지 않겠습니까?

interface MessageBodyConverter {
  /** return a converted body of the original message */
  Object convert(Object body, Message originalMessage);
}

그런 다음 MessageConverter를 만들 수 있습니다.

class MyMessageConverter implements MessageConverter {
  private final MessageBodyConverter converter;

  public Object fromMessage(Message message) {
    if (message instanceof ObjectMessage) {
       return converter.convert(objectMessage.getObject(), message);
    ...
  }
}

그런 다음 해당 MessageConverter 객체를 원하는만큼 깊이 체인 할 수 있습니다. 또한 메시지의 의사 (JMS 준수하지 않음) 구현을 시도하지 않고 원래 JMS 메시지 (헤더 등을 가져 오기 위해)에 액세스 할 수 있습니까?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top