Results 1 to 3 of 3

Thread: Dynamic integration

  1. #1
    Join Date
    Jan 2008
    Posts
    182

    Question Dynamic integration

    OK, so I keep coming back to this project every six months. I'm trying to update to spring integration 2.0.0.M4 from spring integration 1.0.0.M6.

    We have an applications where we want to dynamically provision messaging. I've managed to write some code that can dynamically write to a JMS queue, but the code to read from one is not working.

    Any idea what class/es I should be using?

    For the sender:

    Code:
    	public static SubscribableChannel createChannel(String destinationName,
    			ConnectionFactory connectionFactory) {
    		JmsDestinationBackedMessageChannel channel = new JmsDestinationBackedMessageChannel(
    				connectionFactory, destinationName, false);
    		try {
    			channel.afterPropertiesSet();
    		} catch (Exception e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		return channel;
    	}
    
    ...
    channel.send(message);
    For the receiver this doesn't work:
    Code:
    channel = createChannel(queue, connectionFactory);
    		channel.subscribe(this);
    		EventDrivenConsumer consumer = new EventDrivenConsumer(channel, this);
    		consumer.start();

  2. #2
    Join Date
    Jan 2008
    Posts
    182

    Default

    OK, I can get something going with the horrible code below, but it definately isn't really SpringIntegration... what should I be using?

    Code:
    		listenerContainer = new SimpleMessageListenerContainer();
    		listenerContainer.setConnectionFactory(connectionFactory);
    		listenerContainer.setDestinationName(queue);
    		listenerContainer.afterPropertiesSet();
    		ChannelPublishingJmsMessageListener listener = new ChannelPublishingJmsMessageListener() {
    			@Override
    			public void onMessage(javax.jms.Message jmsMessage, Session session)
    					throws JMSException {
    				System.out.println(jmsMessage);
    				ActiveMQObjectMessage m = (ActiveMQObjectMessage) jmsMessage;
    				ByteSequence q = m.getContent();
    				String s = new String(q.getData());
    				System.out.println(s);
    
    				ObjectInputStream objstream;
    				Object object;
    				try {
    					objstream = new ObjectInputStream(new ByteArrayInputStream(
    							q.getData()));
    					object = objstream.readObject();
    					objstream.close();
    				} catch (IOException e) {
    					throw new RuntimeException("FUDGE");
    				} catch (ClassNotFoundException e) {
    					throw new RuntimeException("FUDGE");
    				}
    
    				GenericMessage<String> gm = (GenericMessage<String>) object;
    				System.out.println(gm.getPayload().toString());
    				handleMessage(gm);
    			}
    		};
    		listener.afterPropertiesSet();
    		listenerContainer.start();
    		JmsMessageDrivenEndpoint end = new JmsMessageDrivenEndpoint(
    				listenerContainer, listener);

  3. #3
    Join Date
    Jan 2008
    Posts
    182

    Default

    OK, I simplified to this, but still not sure if I'm doing the right thing.

    Code:
    			ObjectMessage m = (ObjectMessage) jmsMessage;
    			Object object = m.getObject();
    			GenericMessage<String> gm = (GenericMessage<String>) object;
    			handleMessage(gm);
    			jmsMessage.acknowledge();

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •