Announcement Announcement Module
Collapse
No announcement yet.
SourceAdapter Problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SourceAdapter Problem

    Hi, im developing a tutorial about how to write TargetAdapters and SourceAdapters, in a few days i will publish first one (TargetAdapter).
    Now I m working on SourceAdapter. The problem is that i cannot communicate input to output, let me explain:

    my code is a class that extends from AbstractSourceAdapter and initialize looks like:

    Code:
    final XMPPConnection connection = new XMPPConnection(this.server);
    		try {
    			connection.connect();
    			connection.login(this.user, this.password);
    		} catch (final XMPPException e) {
    			throw new MessageHandlingException("Error starting", e);
    		}
    
    		final PacketFilter packetFilter = new MessageTypeFilter(
    		        Message.Type.chat);
    		connection.createPacketCollector(packetFilter);
    
    		final PacketListener packetListener = new PacketListener() {
    
    			@Override
    			public void processPacket(Packet arg0) {
    				String msn = ((Message) arg0).getBody();
    				IMSourceAdapter.this.sendToChannel(msn);
    			}
    
    		};
    
    		connection.addPacketListener(packetListener, packetFilter);
    And XML configuration looks like:

    Code:
    <channel id="inMessage"></channel>
    
    <beans:bean id="sourceIM" class="test.spring.integration.im.IMSourceAdapter">
    		<beans:property name="user" value="logger"></beans:property>
    		<beans:property name="password" value="logger"></beans:property>
    		<beans:property name="server" value="localhost"></beans:property>
    		<beans:property name="channel" ref="inMessage"></beans:property>		
    		<beans:property name="messageMapper">
    			<beans:bean class="test.spring.integration.im.TextIMMessageMapper"></beans:bean>
    		</beans:property>
    	</beans:bean>
    	
    	<file-target directory="c:\\temp" channel="inMessage"/>
    Well if i execute this code, I receive messages to processPacket method but it seems like they aren't sent to file-target endpoint.

    If i change that code for:

    Code:
    <channel id="inMessage"></channel>
    
    <file-source directory="c:\\temp\\aa" channel="inMessage" poll-period="10000"/>
    	
    <file-target directory="c:\\temp" channel="inMessage"/>
    Obviously works perfect, so i think my problem is in SourceTarget implementation, and i cannot extends from PollableSource because Instant Messaging is 100% asynchronous, doesn't require poll.

    Any idea of what is happen? Thank you very much, and of course when i finish this example, i will publish.

    Thanks.

  • #2
    Sorry, after i write down the message, a light has switched on, the problem was that MessageMapper doesn't receive what he expected, so no message mapper could deal with class. My messagemapper requires an object of type IMMessage, and I was sending a String. But i think that would be great if an exception was thrown telling that the message couldn't be delivered because no mapper was found. Well it is only an idea, i just don't know if it is possible or not.

    Anyway, thank you very much.

    Comment


    • #3
      At some point later today, some changes will be committed that will affect this. The main change is that the source and source-adapter are being more properly separated. You hit one of the main points - some sources are pollable (for those we have the PollableSource interface) while others are event-driven (such as what you are doing).

      Here's the general idea behind the refactoring. A PollingSourceAdapter is being modified to connect a source to a channel and to be driven by a schedule. For example, the constructor is:
      Code:
      public PollingSourceAdapter(PollableSource source, MessageChannel channel, Schedule schedule)
      The MessageBus is responsible for scheduling such an adapter that it discovers within the context. Other source adapters (such as yours) do not require polling and should be wired directly to a channel to which they will send messages.

      You should start to see some of these changes in commits later today and tomorrow.

      Regards,
      Mark

      Comment


      • #4
        Well, then i will post TargetAdapter example, and in next days i will download the new version of spring-integration and I will change my code for adapting to this new version.

        I will send you the url of each post.

        Thanks.

        Comment


        • #5
          Ah, I love this .

          Think about the next generation sysadmins talking to their applications with Jabber! Great stuff; looking forward to the links.

          Comment

          Working...
          X