IS Architectures and Design
Patterns
Erasmus students, 2024-2025
Why messages?
• In some cases we want to be able to communicate in asynchronous
way and not synchronous (RMI/IIOP).
• RMI/IIOP client WAIT for response.
• RMI/IIOP client can not send request if server is NOT AVAILABLE.
Broker
• Messages are handled by message broker
• Client is free of concerning about message delivery… (fire-and-forget)
App2
App Message Broker App3
App1
App1
App4
Broker tasks
• After message is sent it does not block sender.
• It DELIVERS the message. No matter what.
• Handles subscriptions – message can be multiplied and sent to
mltiple subscribers - receivers.
Weaknesses
• Performance
• System complexity
MOM
• Message-oriented Middleware
• Some well established products:
• IBM MQSeries
• Microsoft MSMQ
• Progress SonicMQ
• OpenMQ
• Apache ActiveMQ
• RabbitMQ
• …
• Additional functionalities:
• Guaranteed delivery,
• Load balancing,
• Exception handling,
• …
Delivery guarantee
• Procedure
• MOM persists all messages,
• Messages are sent to receiver,
• After receiver is confirmed message is deleted.
• Suitable for environments where receivers can be offline temporarly.
JMS
• Java Message Service API
• Vendor independent API(s)
• 2 parts:
• Developer API
• SPI (Service Provider Interface) – for driver developers
MOM types
• Publish / subscribe
• Many senders, many receivers.
Sender1 Receiver1
Topic
Sender2 Receiver2
• Point-to-Point
• Message has only one receiver.
• Data structure used: queue (FIFO)
Sender1
Queue Receiver1
Sender2
P2P: Queue
Pošiljatelj 1 Prejemnik 1
Pošiljatelj 2 Prejemnik 2
Pošiljatelj 3 Prejemnik 3
Queue
Pošiljatelj 4 Prejemnik 4
Pošiljatelj N Prejemnik M
PS: Topic
Pošiljatelj 1 Prejemnik 1
Pošiljatelj 2 Prejemnik 2
Pošiljatelj 3 Prejemnik 3
Topic
Pošiljatelj 4 Prejemnik 4
Pošiljatelj N Prejemnik M
JMS communication JMS driver JMS server
2:create
Connection JMS ConnectionFactory
q1
messages
3:create
Session JMS Connection q2
Odjemalec
5:create
1: lookup Producer/Consumer
JMS Session q3
JMS driver
ConnectionFactory 6:send/receive
message JMS Producer
4:lookup
or q4
channel
JMS Consumer
JNDI
JNDI server
Classes to work with
package javax.jms
Vmesnik Point-to-Point Publish/Subscribe
ConnectionFactoryQueueConnectionFactory TopicConnectionFactory
Connection QueueConnection TopicConnection
Destination Queue Topic
Session QueueSession TopicSession
MessageProducer QueueSender TopicPublisher
MessageConsumer QueueReceiver, TopicSubscriber
QueueBrowser
Message types
• TextMessage
• MapMessage
• ObjectMessage
• BytesMessage
• StreamMessage
Message driven bean?
• Message receiver.
• MDB communicates only to topic / queue – not client! → does not
have business interface
EJB server
EJB1
MessageBean
send/
client publish JMS Queue EJB2
MessageBean
JMS Topic
MessageBean EJB3
MDB structure
• No interfacas
• Only implementation class
• Interface javax.jms.MessageListener
• public void onMessage(Message msg)
• Message → BytesMessage, ObjectMessage, TextMessage, StreamMessage or
MapMessage.
• Annotation @MessageDriven
• Can not propagate Exceptions!
• Stateless!
• Can be durable (persistant messages) or non-durable
MDB lifecycle
Sending to Queue
Publishing to Topic
Receiver - blocking
Receiver - blocking
Non-blocking universal receiver
EJB as a receiver
• Message-Driven Beans
• Simplified
• Annotations
• onMessage implementation
• Instance pooling …
Queue
Topic
What is REST?
• Architectural style
• Using HTTP protocol
• We treat application as a set of “resources”
• HTTP verbs vs. method calls
History
• Roy Fielding PhD (2000)
• WS (2000)
exclusive usage og POST
• REST – architectural style
• Distributed services
• Verb – action; Noun - Resource
WS vs. REST services
• WS – action based, operation-based
• REST – resource based
(Representational State Transfer)
• REST web is “resource-centric application”
• Example
• Resource-centric
– URL http://www.bookstore.com/books/
– http://www.bookstore.com/books/0321396855/
Examples
GET /book/222
(SELECT * FROM books WHERE isbn=222)
POST /order
(INSERT INTO orders)
PUT /order/612
(UPDATE orders WHERE id=612)
Request example
GET /resteasy/index.html
HTTP/1.1
Host: jboss.org
User-Agent: Mozilla/5.0
Accept:text/html,application/xhtml+xml,
application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Reponse example
HTTP/1. 1 200 OK
X-Powered-By: Servlet 2.4; JBoss-4.2.2.GA
Content-Type: text/html
<head>
<title>Project JBoss RESTEasy</title>
</head>
<body>
<h1> RESTEasy</h1>
<p> …
Resource management: HTTP methods
• GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE, CONNECT
• GET
• Return resource
• Idempotent operation
• POST
• Create resource
• IS NOT IDEMPOTENT
Resource management: HTTP methods
• PUT CRUD REST
• Change or create resource CREATE POST
• Idempotent operation
READ GET
• DELETE UPDATE PUT
• Delete resource
• Idempotent operation
DELETE DELETE
Java API for RESTful Web Services (JAX-RS)
• Purpose: simplify rest operations
• Annotations
• Resources
• Routing
• URL mapping, metadata mapping
• Value mapping
Basics
• Implement
javax.ws.rs.core.Application
• @ApplicationPath(“..initial url..”)
• Resources: @Path(“/resource”)
• Ustrezne metode pa z:
• @javax.ws.rs.GET
• @javax.ws.rs.PUT
• @javax.ws.rs.POST
• @javax.ws.rs.DELETE
• @javax.ws.rs.HEAD
Example
@Path("/booking")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class BookingResource {
@EJB
Booking ejb;
@GET
@Path("/reservation/{member}")
public List<Reservation> getReservations(@PathParam(“member") String memberCode) {
return ejb.getReservations(memberCode);
}
}
Json Binding
• Standard way of doing JSON serialization
• Annotations
Json Binding
• Serialisation/deserialisation Java objects to/from JSON
JAVA
JSON
public class Knjiga {
private int id;
private String naslov;
private String avtor;
JAX-RS
XML
Objects
JSON
Object-Oriented Design patterns
• design pattern: a solution to a common software problem in a context
• describes a recurring software structure
• is abstract from programming language
• identifies classes and their roles in the solution to a problem
• patterns are not code or designs; must be instantiated/applied
• example: Iterator pattern
• The Iterator pattern defines an interface that declares methods for
sequentially accessing the objects in a collection.
History
• the concept of a "pattern" was first expressed
in Christopher Alexander's work A Pattern
Language in 1977 (2543 patterns)
• in 1990 a group called the Gang of Four or "GoF"
(Gamma, Helm, Johnson, Vlissides) compile a
catalog of design patterns
• 1995 book Design Patterns:
Elements of Reusable Object-Oriented
Software is a classic of the field
Benefits of using design patterns
• patterns are a common design vocabulary
• allows engineers to abstract a problem and talk about that abstraction in isolation
from its implementation
• embodies a culture; domain-specific patterns increase design speed
• patterns capture design expertise and allow that expertise to be
communicated
• promotes design reuse and avoid mistakes
• improve documentation (less is needed) and understandability (patterns
are described well once)
GoF patterns
• Creational Patterns
(abstracting the object-instantiation process)
• Factory Method Abstract Factory Singleton
• Builder Prototype
• Structural Patterns
(how objects/classes can be combined to form larger structures)
• Adapter Bridge Composite
• Decorator Facade Flyweight
• Proxy
• Behavioral Patterns
(communication between objects)
• Command Interpreter Iterator
• Mediator Observer State
• Strategy Chain of Responsibility Visitor
• Template Method
Example: Creational - Singleton
https://en.wikipedia.org/wiki/Singleton_pattern
Example: Structural - Adapter
https://en.wikipedia.org/wiki/Adapter_pattern
Example: Behavioral - Observer
https://en.wikipedia.org/wiki/Observer_pattern