English 中文(简体)
JMS InformationCreator.createMessage () in Grails
原标题:JMS MessageCreator.createMessage() in Grails

我正试图对我的铁路申请实施 j。

I have several JMS consumer in a spring based enviroment listining on an ActiveMQ broker. I wrote a simple test commandline client which creates messages and receives them in an request response manner.

Here is the snippet that sends a MapMessage in Spring JMS way. This works for me as long I am in my spring world.

final String corrID = UUID.randomUUID().toString();
asyncJmsTemplate.send("test.RequestQ", new MessageCreator() 
{
 public Message createMessage(Session session) throws JMSException {
  try {
   MapMessage msg = session.createMapMessage();
   msg.setStringProperty("json", mapper.writeValueAsString(List<of some objects>));     
   msg.setJMSCorrelationID(corrID);
   msg.setJMSReplyTo(session.createQueue("test.ReplyQ"));
   return msg;
  } catch (JsonGenerationException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (JsonMappingException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return null;
 }
});

BUT when I tried to implement this methods to my grails test app I receive some METHOD_DEF exceptions. Sending simple TextMessages via the jmsTemplate.convertAndSende(Queue, Message) provided by the JMS Plugin works.

谁能帮助我? 这一共同问题吗?

Cheers Hans

问题回答

我实际上不试图这样做,就不得不认为这是一个yn子问题。 你真正与这一匿名类别打交道的是,通过关闭,将所有电离辐射器编码纳入电离层电离层的构造。 在格罗维耶,关闭只能作为最后的论据,将其置于功能名称或母体最初的论点之后。

SomeFunction( arg1, arg2) { some code }

这与

SomeFunction( arg1, arg2, { some code } )

你真的希望是把封锁变成一个匿名的电文,我认为你可以通过以下方式做到这一点:

asyncJmsTemplate.send("test.RequestQ", 
          { code in the anonymous block } as MessageCreator );

我在StackOverflow看到这一点,实际上,这提出了一个问题。 阅读所有答复,请见相关内容:。 取代java内部班级的最佳结业?

I have had the same problems and here is my working solution: I have created a new class MyMessageCreator in the src folder which implements the origin JMS MessageCreator interface.

有了这一点,我就能够产生一个新的MyMessageCreator目标,并且可以把创造-Message(慈善会议)职能称为产生新的信息。

为获得本届会议的反对,我使用了jmsTemplate。

public class MyMessageCreator implements MessageCreator {

    @Override
    public Message createMessage(Session session) throws JMSException {
        return session.createMapMessage();
    }

}

这里是相关的农业法典:

Session session = jmsTemplate.getConnectionFactory().createConnection().createSession(false, Session.AUTO_ACKNOWLEDGE)
MapMessage msg = new MyMessageCreator().createMessage(session);

Hope this helps, Mirko





相关问题
handling exceptions IN Action Filters

Is there a better way to handle exceptions that occur inside an Action Filter itself in ASP .NET MVC? There re 2 ways I can think of at the moment. Using a try catch and setting the HTTP Status ...

既可捕获,又可举出例外。

我有一种办法,可以进入亚洲开发银行,因此,我国的亚行在多瑙河航道中的所有 st子都位于一个试捕区。 它正在追捕Kexception

Cross compiler exception handling - Can it be done safely?

I am doing some maintenance on a C++ windows dll library that is required to work with different VC++ compilers (as I don’t want to address different mangling schemes). I have already eliminated any ...

File Handling Issue

I am developing a tool in c#, at one instance I start writing into a xml file continuously using my tool,when i suddenly restart my machine the particular xml file gets corrupted, what is the reason ...

Watch a memory location/install data breakpoint from code?

We have a memory overwrite problem. At some point, during the course of our program, a memory location is being overwritten and causing our program to crash. the problem happens only in release mode. ...

Unit Test for Exceptions Message

Is there a simple (Attribute-driven) way to have the following test fail on the message of the exception. [TestMethod()] [ExpectedException(typeof(ArgumentException))] public void ExceptionTestTest() ...

热门标签