Discussions

J2EE patterns: Factory with JMS and Email

  1. Factory with JMS and Email (5 messages)

    Hi Friends,

    Here is a situation I would like to point out, where by a system is having Human as well as System components interfaces bound together.

    Now a component will have to decide whether to generate an email or a JMS message as response , I hereby propose a Factory pattern that decides the type of response, depending on the recipient address and from address.

    If a '@' symbol encountered in both the addresses, then go for the emailing to a SMTP server, otherwise send a message to the JMS server.

    Regards,

    Istiaque.
    http://techtips.ontheweb.com

    Threaded Messages (5)

  2. Factory with JMS and Email[ Go to top ]

    Why not always send a JMS message and implement a JMS client that sends e-mails in response to certain JMS messages?
  3. Factory with JMS and Email[ Go to top ]

    This way don't u think we shall be writing an application specific to a JMS implementation.
    I may want to have my mailing system receivig the replys from the recipients SMTP server, not the JMS system.

    Let me elaborate the design a bit,

    inteface IMessage
    {
       public void sendMessage(String address, java.util.Hashtable param);
    }
    public class MessageFacade implements IMessage
    {
    //a singleton class
       private MessageFacade messFac = new MessageFacade();
       private MessageFacade()
       {
        
       }
       public static MessageFacade getMessageFacade()
       {
         return messFac;
       }
       public void sendMessage(String address, Hashtable param)
       {
         if(address conatins '@', .com,.net,.org, etc etc)
         {
            call a SMTP and send the message.
         } else {
            call JMS message service.
         }
       }
    }


    class Client
    {
         public Client()
         {
              IMessage iMessage = MessageFacade.getInstance().sendMessage(..,..);
         }
    }
    does all the trick.

    Regards,

    Istiaque.
    http://www.ideas2work.com

    }
  4. Factory with JMS and Email[ Go to top ]

    You might consider making messFac static if you want to compile the above code. Regarding this topic I don't think this is a new 'pattern'. Factory is a pattern indeed. What you have pointed out is a use of the Factory pattern. how is this new ?
  5. Factory with JMS and Email[ Go to top ]

    I think that this idea is not very good just because in the future you can need some other notifying services. And component must not solve what kind of message to send. Otherwise it can reduce application scalability and maintenance. Instead You should use one message center, that you can configure at deployment time and that thus can solve whether to send simple JMS or e-mail or other type of messages. Similiar idea is Apache Log4J - You use general API to log application events and you can configure it to log into simple files,JMS,SMTP etc. But Your components know nothing about their sent messages.
      For this needs, I also propose to use JMS and one fairly complicated MDB to solve this problem. And Your components always will send general JMS messages.
  6. Better way to do is have a configuration file, which tells what are the listener classes for a JMS Topic. Dynamically instantiate them at the startup and let the listener classes implement what they want to do to either send an e-mail or do any activity.